CIL (Common Intermediate Language) is a low-level language used by Microsoft .NET Framework and Mono.
Questions tagged [il]
477 questions
9
votes
4 answers
Is there any IL editor to change the bytecode of an assembly?
I've detected some defects on legacy third party assemblies that we're using on our code decompilind them. I would like to fix them but as I don't have the source code I need to directly modify the bytecode. The changes are really simple (changing…

Ignacio Soler Garcia
- 21,122
- 31
- 128
- 207
8
votes
2 answers
Generic syntactic sugar or true improvement
I have a question regarding the following method calls:
var ctl1 = this.FindControlRecursively("SomeField") as HiddenField;
var ctl = this.FindControlRecursively("SomeField");
Here's IL for these two calls:
IL_0010: ldstr …

Pat Lindley
- 175
- 1
- 9
8
votes
2 answers
cecil: Instruction.Operand types corresponding to Instruction.OpCode.Code value
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…

Keith
- 2,820
- 5
- 28
- 39
8
votes
1 answer
High Performance Cloning
I'm after a means of deep cloning an object graph in a perfomant way. I'm going to have multiple threads cloning a graph extremely quickly such that they can play with some state and throw away the results if they're not interesting, returning to…

Ian
- 33,605
- 26
- 118
- 198
8
votes
1 answer
Generating IL for Recursive Methods
I tried to generate IL for recursive method using following strategy,
Firstly I defined type using following code snippet
private void InitializeAssembly(string outputFileName)
{
AppDomain appDomain = AppDomain.CurrentDomain;
…

Upul Bandara
- 5,973
- 4
- 37
- 60
8
votes
5 answers
What is unsafe in this code?
I am learning about managed and unmanaged code in CLR.
So I wrote this example with C-style pointers in C#:
unsafe static void Main(string[] args)
{
int x;
int* y;
y = &x;
*y = 50;
Console.WriteLine(*y);
…

vldmrrdjcc
- 2,082
- 5
- 22
- 41
8
votes
3 answers
What is the maximal number of methods per .NET class
Title asks it all, actually, but still, for completeness sake:
Hi, I'm writing a small post-compiling tool in the .NET platform, and while trying to optimize it, I've encountered a question I can-not easily find an answer to from the ECMA standards…

damageboy
- 2,097
- 19
- 34
8
votes
2 answers
IL: ldfld vs ldflda
I'm writing a small IL-weaving application using Mono.Cecil, that requires me to manipulate the target assembly on an IL level.
My question is quite simple, but I still find the matter very confusing. What is the practical difference between the…

ShdNx
- 3,172
- 5
- 40
- 47
8
votes
1 answer
how to catch an int
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
{
…

Nitin Chaudhari
- 1,497
- 16
- 39
8
votes
5 answers
Are Delegates more lightweight than classes?
I tried disassembling a C# created executable, but I couldn't come to a conclusion. What I'd like to know is that if for the CLR c#'s delegates are really special entities or just a compiler sugar?
I ask this because I'm implementing a language that…

Waneck
- 2,450
- 1
- 19
- 31
8
votes
1 answer
How to inject IL into a method at runtime
Title more or less says it all. Based on this article, I've come up with this:
public static unsafe void Replace(this MethodBase destination, MethodBase source)
{
IntPtr srcHandle = source.MethodHandle.GetFunctionPointer();
IntPtr dstHandle…

YellPika
- 2,872
- 2
- 28
- 31
8
votes
3 answers
Does initialization of local variable with null impacts performance?
Lets compare two pieces of code:
String str = null;
//Possibly do something...
str = "Test";
Console.WriteLine(str);
and
String str;
//Possibly do something...
str = "Test";
Console.WriteLine(str);
I was always thinking that these pieces of code…

petro.sidlovskyy
- 5,075
- 1
- 25
- 29
8
votes
2 answers
Create a copy of method from IL
I am trying to create a copy of a method during runtime using reflection.
I have the following code.
public static R CopyMethod(Func f, T t)
{
AppDomain currentDom = Thread.GetDomain();
AssemblyName asm = new AssemblyName();
…

Igor Ševo
- 5,459
- 3
- 35
- 80
8
votes
1 answer
Traverse a c# method and anazlye the method body
Whats the easiest way to traverse a methodinfo in c#?
I want to traverse the method body and find field-references and such and retrieves the types.
In System.Reflection there is:
mi.GetMethodBody().GetILAsByteArray()
which is kinda low-level and…

Marcus
- 1,866
- 1
- 20
- 33
8
votes
2 answers
Emit IL code to load a decimal value
I have code like this to emit IL code that loads integer or string values. But I don't know how to add the decimal type to that. It isn't supported in the Emit method. Any solutions to this?
ILGenerator ilGen = methodBuilder.GetILGenerator();
if…

ygoe
- 18,655
- 23
- 113
- 210