Reputation: 33880
Can anyone tell me if there a way to see if an action contains any code?
Action x = new Action(()=>
{
});
should return false, while
Action x = new Action(()=>
{
var x = "i am a string"
});
should return true.
Perhaps using reflection?
Upvotes: 4
Views: 1438
Reputation: 1089
Maybe this will help:
Action x = new Action(() =>
{
var xx = "i am a string";
});
Action x1 = new Action(() =>
{
});
MethodBody mb = x.Method.GetMethodBody();
MethodBody mb1 = x1.Method.GetMethodBody();
byte[] b = mb.GetILAsByteArray();
byte[] b1 = mb1.GetILAsByteArray();
b1 (empty method body) has only 2 bytes, values 0 and 42 meaning nop and return, I think.
Upvotes: 7