Does anybody know tools to view the C# compiler generated code for delegate?
I want to verify the following
class X
{
public event D Ev;
}
Which is compiled to :
class X
{
private D __Ev; // field to hold the delegate
public event D Ev {
add {
lock(this) { __Ev = __Ev + value; }
}
remove {
lock(this) { __Ev = __Ev – value; }
}
}
}
Your question makes no sense, but you're probably looking for Reflector.
EDIT: Now, your question does make sense. You're still looking for Reflector.
However, you'll need to set the Optimization to None in options.
It reveals,
private EventHandler<MyEventArgs> MyEvent;
public event EventHandler<MyEventArgs> MyEvent
{
[MethodImpl(MethodImplOptions.Synchronized)] add
{
this.MyEvent = (EventHandler<MyEventArgs>) Delegate.Combine(this.MyEvent, value);
return;
}
[MethodImpl(MethodImplOptions.Synchronized)] remove
{
this.MyEvent = (EventHandler<MyEventArgs>) Delegate.Remove(this.MyEvent, value);
return;
}
}
Reflector was bought by RedGate and is now a commercial product.
A free alternative is dotPeek:
https://www.jetbrains.com/decompiler/
It's a very capable decompiler with plenty of options and every bit as good as Reflector was at the time it was purchased. I haven't used it since so can't comment on what you get for your money.
Another tool is LINQPad:
http://www.linqpad.net/
It disassembles C# as you type (which is handy) and will show you the CIL. However it won't attempt to decompile that back into C# for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With