首页 > 代码库 > 反射动态调用子类方法

反射动态调用子类方法

//Type type = Type.GetType("Domain.Entitiy." + item.Name);
//object handler = Activator.CreateInstance(type);
//Func<string, QueryStoresOutput> hook = o => ((dynamic)handler).QueryStore((dynamic)o);
//var res = hook(cityCode);


  Type type = Type.GetType("Domain.Entitiy." + item.Name);
  object handler = Activator.CreateInstance(type);
  Func<BusinessSystemSubmitInputModel, QuoteSnapshot> hook =
      o => ((dynamic)handler).GetQuote((dynamic)o);
  var res = hook(model);

 

 

Action<object> hook = message => ((dynamic)handler).HandleMessage((dynamic)message);

反射动态调用子类方法