反射怎么传类型参数?
比如我已知反射类里面有个Class 想传这个类型的参数,本地该怎么去做呢
- C# code
public class RelevanceGoodsItems { public RelevanceGoodsItems(string _totaltitle, string _morelink) { Items = new List<RelevanceGoodsItem>(); TotalTitle = _totaltitle; MoreLink = _morelink; } public string TotalTitle; public string MoreLink; public List<RelevanceGoodsItem> Items; }
完整代码, 反射里面有个方法
- C# code
namespace ADO{ public class Test { //这个是我要反射的方法 public static string GetMethodByRef(RelevanceGoodsItems InputValue) { return InputValue.TotalTitle; } public class RelevanceGoodsItems { public RelevanceGoodsItems(string _totaltitle, string _morelink) { Items = new List<RelevanceGoodsItem>(); TotalTitle = _totaltitle; MoreLink = _morelink; } public string TotalTitle; public string MoreLink; public List<RelevanceGoodsItem> Items; } }}//下面是我本地的代码public class LocalTest{ RelevanceGoodsItems items = new RelevanceGoodsItems("我是标题", ""); MethodInfo mi = _Compiled.GetType().GetMethod("GetMethodByRef", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); return mi.Invoke(_Compiled, new Object[1] { items }).ToString(); //我本地同时建立了一个跟反射类参数同样的类 public class RelevanceGoodsItems { public RelevanceGoodsItems(string _totaltitle, string _morelink) { Items = new List<RelevanceGoodsItem>(); TotalTitle = _totaltitle; MoreLink = _morelink; } public string TotalTitle; public string MoreLink; public List<RelevanceGoodsItem> Items; }}
我这样调用会提示类型“RelevanceGoodsItems”的对象无法转换为类型“ADOGuy._Evaluator+RelevanceGoodsItems”。
请问该怎么传参呢?
[解决办法]
[解决办法]