本文介绍了如何检查是否一个泛型参数是动态的,在.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.

这篇关于如何检查是否一个泛型参数是动态的,在.NET 4.0中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 15:31