简体   繁体   English

在反射C#中传递参数

[英]pass parameters in reflection C#

i have such code 我有这样的代码

Bitmap b = new Bitmap(@"d:\0.bmp");
tessnet2.Tesseract ocr = new tessnet2.Tesseract();
ocr.DoOCR(b, Rectangle.Empty);

the i try to make it through reflection 我试图通过反思

Assembly a = Assembly.Load("tessnet2_32");
Type myType = a.GetType("tessnet2.Tesseract");
MethodInfo mymethod = myType.GetMethod("DoOCR");
Object obj = Activator.CreateInstance(myType);
mymethod.Invoke(obj, null);

how can i pass parameters? 如何传递参数?

mymethod.Invoke(obj, new object[] { b, Rectangle.Empty });

that would be through the MethodInfo.Invoke(obj, object[] parameters ) method 通过MethodInfo.Invoke(obj, object[] parameters )方法

so myMethod.Invoke(obj, new object[] {b, Rectangle.Empty}); 所以myMethod.Invoke(obj, new object[] {b, Rectangle.Empty});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM