il

How does the Conditional attribute work?

♀尐吖头ヾ 提交于 2020-01-01 05:08:12
问题 I have some helper methods marked with [Conditional("XXX")] . The intent is to make the methods conditionally compile when only the XXX conditional compilation symbol is present. We're using this for debugging and tracing functionality and it works quite well. During my research on how the conditional compilation works, I found several sources stating methods tagged with the Conditional attribute will be placed in the IL but calls to the methods will not be executed. How does code get

cecil: Instruction.Operand types corresponding to Instruction.OpCode.Code value

最后都变了- 提交于 2019-12-31 22:40:14
问题 Is there any documentation or is there a part of the cecil source code that I can consult to get a comprehensive view of which Operand types cecil will use for a given Code value? Eg: I can glean from MethodBodyRocks that Ldloc takes an Operand of type VariableDefinition , but I haven't been able to track down this down for some of the other instruction codes. 回答1: You can look at the definition of every OpCode in the OpCodes.cs file. E.g. for Ldloc you would see OperandType.InlineVar 回答2: To

Why does C# -> CIL have a label on every instruction?

雨燕双飞 提交于 2019-12-31 02:44:10
问题 When using ILDASM.exe on a compiled C# program, it shows that there is a label for every instruction within methods. For example: IL_0001: ldc.i4.4 IL_0002: stloc.0 IL_0003: ldc.r8 12.34 IL_000c: stloc.1 IL_000d: ldc.r8 3.1415926535897931 IL_0016: stloc.2 IL_0017: ldstr "Ehsan" IL_001c: stloc.3 IL_001d: ret Why is this? Is it not inefficient to do this or does the CIL compiler optimize these labels itself? 回答1: Labels are not present in the compiled CIL. They are displayed for your

What is your recommendation for a good book on the .NET CLR and CIL? [closed]

倾然丶 夕夏残阳落幕 提交于 2019-12-30 04:44:10
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . Do you know any good book about the workings of the CLR, the .NET Framework and CIL as opposed to any specific .NET language? 回答1:

Implementing an Interface on a dynamic type with events

醉酒当歌 提交于 2019-12-24 17:06:57
问题 I am taking in an interface, looping through the .GetEvents() return array and attempting to implement the event on my dynamic type. At the point when I try to call TypeBuilder.CreateType(), I am greeted with this lovely error: "Application method on type from assembly is overriding a method that has been overridden." If I comment out the typeBuilder.DefineMethodOverride calls that attempt to implement the interface methods, at the poin when I attempt to subscribe to the event I get the error

Casting items of a collection with code generation

偶尔善良 提交于 2019-12-24 08:38:48
问题 I'm doing code generation with C# and I would like to cast a backing field inside a getter. Here is an example: public class Potato { } public class ProxyPotato : Potato { } public class Stew { private ICollection<ProxyPotato> _proxyPotatoes; //This is the code I would like to generate (specialy the cast part) public ICollection<Potato> Potatoes { get { return _proxyPotatoes.Cast<Potato>().ToList(); } } } I have this code which can generate a property but I don't know how to execute a Cast:

How does Reflector decompile code?

半城伤御伤魂 提交于 2019-12-24 07:03:20
问题 How do tools like the Red Gate Ant Profiler or the Reflector convert IL into C# or VB.NET code? I recently noticed that the Red Gate Ant Profiler does not generate the same source code that was written originally. It generated a while loop where I had used a foreach . That made me think. I opened Reflector.exe itself in Reflector but their code is mostly (not all of it) obfuscated. 回答1: Decompilers in general work by looking at the IL and constructing source code which is semantically

How is non-virtual instance method inheritance resolved?

痞子三分冷 提交于 2019-12-23 22:09:04
问题 Quoted from CLR via C#, it reads to me as if call would search for the method that is defined by a base type at runtime via CLR. Then call IL instruction is used to call an instance or virtual method, you must specify a variable that refers to an object. The type of the variable itself indicates which type defines the method that the CLR should call. If the variable's type doesn't define the method, base types are checked for a matching method. and When calling a non-virtual instance method,

Does the mono runtime already handle tail call optimisation as required by the IL spec?

梦想与她 提交于 2019-12-23 20:13:03
问题 I know that by this infamous post http://flyingfrogblog.blogspot.com/2009/01/mono-does-not-support-tail-calls.html the mono runtime did not offer tail call elimination as required by the IL. Has this changed since? 回答1: No, not yet. There's some work-in-progress on adding it, though : http://www.mail-archive.com/mono-devel-list@lists.ximian.com/msg24438.html (wish me luck ;-) ). 来源: https://stackoverflow.com/questions/3816148/does-the-mono-runtime-already-handle-tail-call-optimisation-as

how to catch an int

核能气质少年 提交于 2019-12-23 07:47:17
问题 I am using IL to throw an Int32 and catch it. This is just out of curiosity, I am not trying to achieve anything, so please dont tell me to throw an Exception instead of int. .method private hidebysig static void Main(string[] args) cil managed { .entrypoint // Code size 40 (0x28) .maxstack 2 .locals init (object V_0, int32 V_1) IL_0000: nop .try { IL_0001: nop IL_0002: ldsfld int32 ConsoleApplication3.Program::i IL_0007: throw } // end .try catch [mscorlib]System.Object { IL_0008: stloc.0 IL