使用自定义类作为参数从 MethodInfo 调用方法
我有这样的场景: 一个具有一些属性的自定义类(客户),如下所示:
public class Customer
{
public int Handler { get; set; }
public string Name { get; set; }
}
一个具有方法的自定义类,如下所示:
public class CustomerMethods
{
public static void Insert(Customer customer)
{
//Do Something...
}
}
因此,我将加载一个包含一些信息的文本文件,例如类名称、属性名称和属性值。 但是,真正的问题是,在设置 Handler 和 Name 属性的值后,如何从 CustomerMethods 类调用 Insert 方法并将 Customer 类作为参数传递?
哦,我差点忘了,我试图避免条件语句,因为我有 100 多个类。 /o\ 各位,如果您需要更多信息,请告诉我...
I have this scenario:
One custom class (Customer) with some properties, like this:
public class Customer
{
public int Handler { get; set; }
public string Name { get; set; }
}
One custom class with the Method, like this:
public class CustomerMethods
{
public static void Insert(Customer customer)
{
//Do Something...
}
}
So, I will load a text file with some info, like class name, property name and property value.
But, the real problem is, how can I invoke the Insert Method from CustomerMethods class and pass Customer class as parameter after set the values of Handler and Name properties?
Oh, I almost forget, I am trying to avoid conditionals, because I have 100+ classes. /o\
Ty all, if you need more info, just tell me plz...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
但是,如果可能的话,您应该尝试重构您的设计并避免这种情况。
However, you should try to refactor your design and avoid this, if possible.
我仅使用这些字符串来调用静态插入方法
WindowsFormsApplication1.Form1+CustomerMethods
WindowsFormsApplication1.Form1+Customer
插入
I used only these strings to call static Insert method
WindowsFormsApplication1.Form1+CustomerMethods
WindowsFormsApplication1.Form1+Customer
Insert