A
AxlsPixel
Hi All,
I have a class (called CTestClass) within which I have a method
(Foo). This method has the following signature:
Foo(int x, int y, ref int z)
I am attempting to use reflection to invoke this method but before
doing that I want to use Type.GetMethod to bind to it and validate
it's signature. The problem is this binding fails due to the ref
parameter. I have tried using the ParameterModifier structure. However
I ran across the following documentation in MSDN:
================
Although the default binder does not process ParameterModifier (the
modifiers parameter), you can use the abstract
System.Reflection.Binder class to write a custom binder that does
process modifiers. ParameterModifier is only used when calling through
COM interop, and only parameters that are passed by reference are
handled.
The types array and the modifiers array have the same length. A
parameter specified in the types array can have the following
attributes, which are specified in the modifiers array: pdIn, pdOut,
pdLcid, pdRetval, pdOptional, and pdHasDefault, which represent [In],
[Out], [lcid], [retval], [optional], and a value specifying whether
the parameter has a default value. A parameter's associated attributes
are stored in the metadata and are used for interoperability.
===============
With this in mind I have the following question,s:
1. Can the ParameterModifier structure be used with non-COM i.e.
..NET class methods?
2. Does the default implementation of Type.GetMethod use this
structure? The documentation suggests writing a custom binder. Where
does that come into the picture?
3. If I can simply call Type.GetMethod without any having to
implement any other interface then how would I go about invoking
Type.GetMethod in the case of my function "Foo" specifically how do I
construct the ParameterModifier array to pass as an argument?
4. Is there a simpler way to achieve this? (This probably should
have been #1 )
Thanks,
Rudolph
I have a class (called CTestClass) within which I have a method
(Foo). This method has the following signature:
Foo(int x, int y, ref int z)
I am attempting to use reflection to invoke this method but before
doing that I want to use Type.GetMethod to bind to it and validate
it's signature. The problem is this binding fails due to the ref
parameter. I have tried using the ParameterModifier structure. However
I ran across the following documentation in MSDN:
================
Although the default binder does not process ParameterModifier (the
modifiers parameter), you can use the abstract
System.Reflection.Binder class to write a custom binder that does
process modifiers. ParameterModifier is only used when calling through
COM interop, and only parameters that are passed by reference are
handled.
The types array and the modifiers array have the same length. A
parameter specified in the types array can have the following
attributes, which are specified in the modifiers array: pdIn, pdOut,
pdLcid, pdRetval, pdOptional, and pdHasDefault, which represent [In],
[Out], [lcid], [retval], [optional], and a value specifying whether
the parameter has a default value. A parameter's associated attributes
are stored in the metadata and are used for interoperability.
===============
With this in mind I have the following question,s:
1. Can the ParameterModifier structure be used with non-COM i.e.
..NET class methods?
2. Does the default implementation of Type.GetMethod use this
structure? The documentation suggests writing a custom binder. Where
does that come into the picture?
3. If I can simply call Type.GetMethod without any having to
implement any other interface then how would I go about invoking
Type.GetMethod in the case of my function "Foo" specifically how do I
construct the ParameterModifier array to pass as an argument?
4. Is there a simpler way to achieve this? (This probably should
have been #1 )
Thanks,
Rudolph