如何检查是否一个泛型参数是动态的,在.NET 4.0中
问题描述:
我有一个类 ObjectMapper< T>
。有没有办法在.NET 4.0中说,如果的typeof(T)
是动态
?我希望能够确定一个成员方法的类是否被初始化为新ObjectMapper&LT内部;动态>()
与新ObjectMapper< SomeConcreteClass> ()
。
I have a class ObjectMapper<T>
. Is there any way in .NET 4.0 to tell if typeof(T)
is dynamic
? I want to be able to determine inside a member method whether the class was initialized as new ObjectMapper<dynamic>()
vs. new ObjectMapper<SomeConcreteClass>()
.
答
为此,您需要检查,如果一个实例的类型是 IDynamicMetaObjectProvider
,也可以检查是否类型实现 IDynamicMetaObjectProvider
。
You do this by checking if an instance is of type IDynamicMetaObjectProvider
or you can check whether the type implements IDynamicMetaObjectProvider
.