tags:

views:

87

answers:

1

I am currently using Mono Cecil to extract data from C# projects. Now I need to check whether a field is read or written to in each method.

How can tell from the CIL instruction that a field is being read or written to?

Cos I doubt there a library in Mono Cecil similar to Assignment in Eclipse's JDT that allows me to extract the left hand side and right hand side. If there is, then I can just work from there.

+2  A: 

The instruction for direct field stores is stfld, so you'll have to look out for that.

Note that fields can also be indirectly written to via pointers (both * and & kind), which is impossible to detect in the most general case (as pointer can come from the outside).

Pavel Minaev
What do u mean by "as pointer can come from the outside"? Can u give an example, thx? I know a bit abt pointers, but not familiar with it.
yeeen
Pavel Minaev
I found out that ldfld and stfld only works for getters and setters.For other read and store (other than pointers), u hv to use ldsfld and stsfld I think. I tried out the eg u gave and got ldflda when the method is called.
yeeen
It seems like ldfld and stfld are for non-static and ldsfld and stsfld are for static. I tried it with non-static fields and saw the difference. Thx for ur help.
yeeen