我有一个项目在MVC C#code-first。我想将一个类型传递给我的方法。我的方法需要一个班才能工作。但我不想通过一门课 - 我希望它是动态的。有没有可能?C#类型到泛型类
这是我的代码;
string item ="PERSON" // item is a parametric I give the table name to get the type of table
Assembly asm = Assembly.Load("ProjectName");
Type entityType = asm.GetType(String.Format("NameSpace.Model.{0}", item));
var test = LINQDynamic<>.GetQueryResult(ssa,entityType,ddd); // In LINQDynamic<> I want to use entityType like that LINQDynamic<entityType> but it's not acceptable what can I make the convert type to generic?..Because table name is parametric.Is it possible to convert that type?
public class LINQDynamic<TEntity> where TEntity: class
{
public static object GetQueryResult(object pkKey,Type type, params object[] pkKeys)
{
//TODO
}
}
的可能的复制[如何使用反射来调用泛型方法?(http://stackoverflow.com/questions/232535/how-to-use-reflection-to-call-generic-method) – kai
是的,可能是一样的。但我的表名是动态的。我怎样才能转换或如何使用反射来创建字符串表名称到真正的类传递给LINQDynamic <这里是我想要动态类>。 –