I have an application in which I have a method that takes a PropertyInfo parameter and would like to call this method from IL. For example, for similar methods using MethodInfo, I can create an intermediate method using RuntimeMethodHandle and using GetMethodFromHandle . IL can then use the Ldtoken to transmit the descriptor.
However, no equivalent marker metadata exists for properties. I can understand why this may be so (since properties are just a way to combine methods together and never be "called" from IL), but there are certain property metadata associated with the type. I have access to this property metadata in Emit-time, so I would like to be able to pass this directly without resorting to Reflection by name at runtime (i.e. emit Reflection calls GetProperty, taking the line that will be executed in runtime .) Is there a way to do this?
In the request in the comments, here is the application:
I am creating an adapter class that provides a property reference as its component bits through the bool this[int index] property. My application compiles PLC code to a .NET assembly, and so I am trying to create diagnostic accessors that approximate the easy bitwise access provided by the PLC (where you write MyTag.2 to indicate bit 2 of the MyTag tag.) This syntax cannot be used for consumption on C #, but PLC.GetBits().MyTag[2] is a reasonable approximation.
My original approach was implemented using PropertyInfo (that's how I came across this problem), but I can, of course, get around it by passing the applicable metadata from PropertyInfo as a few parameters. I was just curious to know if it is possible to pass PropertyInfo directly, since I have not come across this before.
source share