Comments
5 comments
-
Reflector won't do the translation that you want for the anonymous type. In the IL the anonymous type is constructed using a constructor argument.
var foo = new {A = "jajaj2"};
is generated as a callAnonymousType0<string> type = new AnonymousType0<string>("jajaj2");
so you'd have to do analysis to determine that the constructor argument is referring to the property.
Reflector recognises the anonymous types, causing it to emit the 3.0 syntax, by looking for the prefix "<>f__" on the type name. I managed to get the latter form of the construction by using ildasm, removing the prefix and then using ilasm to reconstruct the assembly but that trick doesn't get you all the way to what you want. -
Well, Clive, thank you very much for the answer!
Оne more question.
How to manage extension methods? I want Reflector to generate old-style call:IEnumerable<string> namesStartingWithA = Enumerable.Where( names, delegate(string n) { return n.StartsWith("A"); });
instead of 3.0 syntax:var namesStartingWithA = names.Where(name => name.StartsWith("A"));
May be, it's worth to add two different items (C# 2.0 and C# 3.0) insted of the only one (C#) in language choise combobox? -
I think you're looking for the View/Options/Disassembler/Optimization combobox.
In Reflector 5.1.5, setting this optimization level to 3.5 makes some code appear asstring[] names = new string[] { "a" }; IEnumerable<string> namesStartingWithA = from n in names where n.StartsWith("A") select n;
Changing the level to .NET 2.0 givesIEnumerable<string> namesStartingWithA = new string[] { "a" }.Where<string>(delegate (string n) { return n.StartsWith("A");
-
Clive Tong wrote:
IEnumerable<string> namesStartingWithA = new string[] { "a" }.Where<string>(delegate (string n) { ...
Here we rid of (I'm not sure how it should be in English) type inference and lambdas, but extension method (Where) still remain. I need this transform:IEnumerable<string> namesStartingWithA = Enumerable.Where<string>(new string[] { "a" }, delegate (string n) { ...
-
Hi all,
I am creating Window Application using c#.net.
I want to show message box with error icon on button click.
For showing message box the code is
MessageBox.Show("Error");
But What to do for including error icon?
Add comment
Please sign in to leave a comment.
I've got an assembly compiled by C# 3.0 compiler targeting to .NET Framework 2.0.
I'd like to get C# 2.0 compliant code, but Reflector gives only C# 3.0 code. How can I overcome this problem?
For example, given this C# 3.0 source code (“Func†and “Where†are custom, not from FCL 3.5): I build an assembly targeting .NET Framework 2.0.
Then I'd like to disassemble to C# 2.0 code, a kind of:
But I've got something like this:
Do I need an older version of Reflector, which doesn't generate C# 3.0 code, limiting with C# 2.0 one?
Thanks in advance.
——
Victor