tags:

views:

30

answers:

2

Is there a way to call a method from a class and passing on some parameters with getType() by passing on the objectname of the class?

    public void ForeachInsert(object tblnaam, string error)
    {
        tblnaam.GetType().GetMethod("nameOfMethod");
//where to place string error?
    }
A: 

Yes, there is - this is all part of Reflection. Once you have the MethodDescriptor you can use it to execut ethe method on a specific class instance and turn int parameters.

Check the content of your tblnaam - it is not "object" but should be a MethodInfo actually.

TomTom
+3  A: 
MethodInfo mi = tblnaam.GetType().GetMethod("nameOfMethod");
object myResukt = mi.Invoke(tbknaal,your_parameters);

Invoke method : http://msdn.microsoft.com/en-us/library/a89hcwhh.aspx

remi bourgarel
+1, and when mi should be null, he has to use BindingFlags (for private members, ...)
tanascius