c#-3.0

Implement Not in expression trees, .net 4

纵然是瞬间 提交于 2020-01-13 11:01:56
问题 Is it possible to implement a ! (not) using expression trees. I'm interested in creating a C# eval class which will parse and evaluate logical expressions which contain true, false, ||, && and !. I know that && and || are currently supported by .NET 4 expression trees, but I was wondering if their is a way to implement summat like !(x && y) || z where z=false, y=true and z=false. Currently I'm using a standard stack based tokenizer, parser, evaluator to evaluate these types of expression but

Implement Not in expression trees, .net 4

僤鯓⒐⒋嵵緔 提交于 2020-01-13 11:01:36
问题 Is it possible to implement a ! (not) using expression trees. I'm interested in creating a C# eval class which will parse and evaluate logical expressions which contain true, false, ||, && and !. I know that && and || are currently supported by .NET 4 expression trees, but I was wondering if their is a way to implement summat like !(x && y) || z where z=false, y=true and z=false. Currently I'm using a standard stack based tokenizer, parser, evaluator to evaluate these types of expression but

Find the highest number in a set to be rounded down, and round it up instead

自古美人都是妖i 提交于 2020-01-13 02:17:34
问题 As the title describes, I have a set of objects - call them Allocations - which contain a description & a number. All numbers in the set add up to 100%, but for display purpose I sometimes round to a whole percent. In some edge cases, having rounded the numbers I end up with 99%. Example: Description | Actual | Rounded =============================== Allocation A | 65.23% | 65% Allocation B | 25.40% | 25% Allocation C | 7.95% | 8% Allocation D | 1.42% | 1% ===============================

What fluent interfaces have you made or seen in C# that were very valuable? What was so great about them?

折月煮酒 提交于 2020-01-11 15:29:10
问题 "Fluent interfaces" is a fairly hot topic these days. C# 3.0 has some nice features (particularly extension methods) that help you make them. FYI, a fluent API means that each method call returns something useful, often the same object you called the method on, so you can keep chaining things. Martin Fowler discusses it with a Java example here. The concept kooks something like this: var myListOfPeople = new List<Person>(); var person = new Person(); person.SetFirstName("Douglas").SetLastName

How to get IE version info in Winform? [duplicate]

半世苍凉 提交于 2020-01-10 01:40:10
问题 This question already has answers here : Detect IE version from a WinForms application (5 answers) Closed 6 years ago . I am developing an winform application in .NET framework 3.5, using C#. In the application I need to display the IE version number, installed on the machine on which it runs. How can I do that, can anybody tell me? 回答1: You can read the version from the registry: var ieVersion = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Internet Explorer").GetValue("Version");

Extension methods require declaring class to be static

僤鯓⒐⒋嵵緔 提交于 2020-01-09 03:44:05
问题 Why do extension methods require the declaring class to be static? Is it a compiler requirement? 回答1: It's dictated in the language specification, section 10.6.9 of the C# 4 spec: When the first parameter of a method includes the this modifier, that method is said to be an extension method. Extension methods can only be declared in non-generic, non-nested static classes. The first parameter of an extension method can have no modifiers other than this, and the parameter type cannot be a

How to make .exe file programmatically set to run as admin always in vista?

爷,独闯天下 提交于 2020-01-07 08:20:30
问题 I have written a winform application in C#. When I run the program for some functionality it required admin permission. After Installation If I set the .exe file to run as admin manually (by clicking right mouse button on .exe file) then my program run perfectly. Now I need user not to set the run as admin property after installation by clicking right mouse button. I need to set this programaticaly somewhere in the code that user no need to bother about this. This specific problem is only

Since Modified Header in c#

主宰稳场 提交于 2020-01-06 19:48:51
问题 Am saving Webpages from webbrowser control to the directory like below code. Now i want to check all the webpages daily that is modified or not. if it is modified have to update or else leave it. here i tried something in console application. static void Main(string[] args) { Uri myUri = new Uri("http://www.google.com"); // Create a new 'HttpWebRequest' object with the above 'Uri' object. HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(myUri); // Create a new 'DateTime'

I got the problem in Crystal Report- Error Messsage:Load report failed

蓝咒 提交于 2020-01-06 06:57:32
问题 I got the problem in Crystal Report- Error Messsage:Load report failed. how to solve this issue??. 回答1: If your report is running for awhile and then falls over make sure you Dispose it....... if(myReport != null) { myReport .Close(); myReport .Dispose(); } 回答2: You can call show data on report in DataBinding and Navigate methods. protected void CrystalReportViewer1_DataBinding(object sender, EventArgs e) { this.ShowReportData(); } protected void CrystalReportViewer1_Navigate(object source,

LINQ to SQL ObjectDisposedException on entity that never asked for

落花浮王杯 提交于 2020-01-06 04:54:12
问题 I have this strange behavior. Im Loading some entities in a List<> and append to a grid. When double click the grid i take the row cast to the entity and append to a property. I have changed some things in my database and code and now i get this exception while i never wanted to check something on this Entity Reference. Any Ideas? 回答1: This seems to happen to me when I try to access a property that isn't one of the columns on the database table that the entity is derived from. For example,