Marc Gravell escribió:
> See my other post; I recommend the "branch to a generic method" approach, as
> it means you only use reflection briefly to change to the second method;
> this means that the code within the method *accessed* via reflection can be
> fully compiled and optimised, and use generic syntax rather than reflection.
Ok this solution finally works for me. Thanks very much.
> Note also that the inner-method would typically be private, so would require
> a binding-flag; I only made it public to make it easy to obtain via
> GetMethod().
But I don't understand this, if I make the method private (which I think
it's the correct way) I can't access it with GetMethod, how can I do it?
Regards.
--
Ympostor - 21 Nov 2006 10:28 GMT
Ympostor escribió:
> But I don't understand this, if I make the method private (which I think
> it's the correct way) I can't access it with GetMethod, how can I do it?
Nevertheless, I have done it with:
BindingFlags.Static | BindingFlags.NonPublic
However, isn't there a way to obtain the MethodInfo statically?
Something like this:
GetMethod(MyClass.MyStaticMethod);
Thanks again.
--
Marc Gravell - 21 Nov 2006 11:10 GMT
If the method was non-generic (or we knew the T in advance), then you may be
able to do this by declaring a matching delegate signature, creating a
delegate pointing to the method, and then inspecting the delegate instance's
Method property (a MethodInfo).
However, AFAIK it is only possible to do this for concrete methods, and you
need to reference the generic method definition (not a closed implementation
there-of); so I don't know if it can be done (how, for instance, would you
declare the variable for this step?
There may be a non-delegate way of accessing the method, but given that we
are using reflection anyhow, an extra GetMethod isn't likely to be much of
an issue.
Marc