Determining if a .NET type is dynamic (created using Reflection.Emit)
Posted
by Diego Mijelshon
on Stack Overflow
See other posts from Stack Overflow
or by Diego Mijelshon
Published on 2010-04-23T16:45:15Z
Indexed on
2010/04/23
17:23 UTC
Read the original article
Hit count: 453
While the .NET 4 framework provides the Assembly.IsDynamic
method, that's not the case with .NET 2.0/3.5.
The use case is simple: for logging purposes, I want to determine the underlying type name of an entity that might be wrapped by a dynamic proxy without having any references to NHibernate or Castle (which know about the proxy)
For example, I might have a CatProxYadaYada
, but I'm interested in Cat
.
What's the easiest way to get that type? I was thinking of this skeleton:
var type = obj.GetType();
while (IsProxy_Dynamic_Whatever(obj))
type = type.BaseType;
return type;
© Stack Overflow or respective owner