How to check if a generic parameter is dynamic in .NET 4.0

那年仲夏 提交于 2020-01-01 08:26:09

问题


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>().


回答1:


You do this by checking if an instance is of type IDynamicMetaObjectProvider or you can check whether the type implements IDynamicMetaObjectProvider.




回答2:


There is no CLR type called dynamic. The C# compiler makes all dynamic values of type object and then calls custom binding code to figure out how to handle them. If dynamic was used, it will show up as Object.



来源:https://stackoverflow.com/questions/3277419/how-to-check-if-a-generic-parameter-is-dynamic-in-net-4-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!