我有一个通用的方法
bool DoesEntityExist<T>(Guid guid, ITransaction transaction) where T : IGloballyIdentifiable;
Run Code Online (Sandbox Code Playgroud)
如何以下列方式使用该方法:
Type t = entity.GetType();
DoesEntityExist<t>(entityGuid, transaction);
Run Code Online (Sandbox Code Playgroud)
我一直收到愚蠢的编译错误:
找不到类型或命名空间名称't'(您是否缺少using指令或程序集引用?)
DoesEntityExist<MyType>(entityGuid, transaction);
Run Code Online (Sandbox Code Playgroud)
完美的工作,但我不想使用if指令每次调用具有单独类型名称的方法.
我有一个像这样的Generic类:
public class Repository<T> {...}
Run Code Online (Sandbox Code Playgroud)
我需要用字符串来实例...示例:
string _sample = "TypeRepository";
var _rep = new Repository<sample>();
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?这甚至可能吗?
谢谢!