c# 对COM+对象反射调用时地址参数处理

    技术2022-05-11  23

    使用反射的方式调用组件里面的方法,经常会遇见一些象地址参数的处理,在C#中表现为ref参数,比如用C#写了一个装配件,里面有一个方法openProcedure(string ProcName,int paraCount,ref string[] parameters),最后有一个ref参数,反射调用代码写法如下:

    try   {    DataSet ds=new DataSet ();

        Type objType;    object objBinding;

        objType = Type.GetTypeFromProgID("CSGPDBAccess.CSGPDBAccess");    objBinding = Activator.CreateInstance(objType);

        Type[] paramTypes = new Type[] {Type.GetType("System.String"), Type.GetType("System.Int32"), Type.GetType("System.String[]&")};       MethodInfo m = objType.GetMethod("openProcedure",paramTypes);        object[] args = new object[3];     args[0] = "Test";    args[1] = 1;    args[2] = new string[]{"0052005"};       ds=(DataSet)m.Invoke(objBinding,args);       if(ds.Tables.Count>0 )    {     dataGrid1.DataSource=ds.Tables[0].DefaultView ;     }   }   catch(TargetInvocationException ee)   {    MessageBox.Show(ee.Message);    }


    最新回复(0)