December 2001
Intermediate to advanced
416 pages
8h 16m
English
The overloaded Invoke() method of the MethodInfo and ConstructorInfo classes allows us to execute the member reflected by the object of either class. To do this, we must build up an object array with the parameters to pass into the method. If it is an instance method, we must also provide an object of that type. Let's look at an example.
Our method has the following signature and return type:
static public bool
invokeMethod( string type, string method, object[] args ){}
First we retrieve a Type object of the specified type. If it cannot be found, we return false:
Type t = Type.GetType( type ); if ( t == null ) return false;
Next we retrieve the method. Again, if we can't find it, we return false. (I can ...
Read now
Unlock full access