I am using castle DynamicProxy and was wondering if there is a way of detecting if a Type is a proxy without referencing Castle DynamicProxy?
So while I am using Castle DynamicProxy as an example I would like code that would work for any in memory generated type.
var generator = new ProxyGenerator();
var classProxy = generator.CreateClassProxy<Hashtable>();
Debug.WriteLine(classProxy.GetType().Is....);
var interfaceProxy = generator.CreateInterfaceProxyWithoutTarget<ICollection>();
Debug.WriteLine(interfaceProxy.GetType().Is....);
Thanks
so far i have this fugly code
private static bool IsDynamic(Type type)
{
try
{
var location = type.Assembly.Location;
return false;
}
catch (NotSupportedException)
{
return true;
}
}