我有一个Dictionary<Type, Dictionary<Guid,Component>>外部字典的键是内部存储的对象的类型.
我想用泛型方法获取内部字典中的一个对象.就像是:
public T getObject<T>(Guid id, ???/*typeof(T) passed here*/) where T : Component
Run Code Online (Sandbox Code Playgroud)
如何将第二个参数约束为typeof(T)?
正如@Chirs Pickford所说; 首先不需要接收额外的参数.
当你有这样的通用方法:
public T getObject<T>(Guid id) where T : Component
{
// you can grab typeof(T) like this
var type = typeof(T);
}
Run Code Online (Sandbox Code Playgroud)