lundi 2 mars 2015

C# Reflection - How to create and pass parameters in by name

I've basically done a foreach loop on the parameters for a method.



MethodInfo objMethoda = method;// typMyService.GetMethod("GetBySystemWarrantyId", Type.EmptyTypes);
ParameterInfo[] pars = objMethoda.GetParameters();
foreach (ParameterInfo p in pars)
{
Console.WriteLine("{0} {1}",p.ParameterType , p.Name);
}

Okay create yay this works, however when I try to invoke it I get parameters don't match.


Basically my method has 5 parameters



  • System.String whereClause

  • System.String orderBy

  • System.Int32 start

  • System.Int32 pageLength

  • System.Int32& totalCount


totalCount is an out. can I create those arguments and pass it into the method? var dataTableObjecta = objMethoda.Invoke(oMyServicea, null);


for example: the values in order would be



"1=1"
""
0
100000
out totalCount




Aucun commentaire:

Enregistrer un commentaire