public virtual Type GenerateCode(Type[] interfaces, Type targetType)
{
if (Context.HasMixins)
{
_mixins = Context.MixinsAsArray();
Type[] mixinInterfaces = InspectAndRegisterInterfaces(_mixins);
interfaces = Join(interfaces, mixinInterfaces);
}
//interfaces = AddISerializable(interfaces);
interfaces = AddInterfaces(new Type[] {typeof(ISerializable), typeof(IProxy)}, interfaces);
ReaderWriterLock rwlock = ModuleScope.RWLock;
rwlock.AcquireReaderLock(-1);
Type cacheType = GetFromCache(targetType, interfaces);
if (cacheType != null)
{
rwlock.ReleaseReaderLock();
return cacheType;
}
rwlock.UpgradeToWriterLock(-1);
try
{
cacheType = GetFromCache(targetType, interfaces);
if (cacheType != null)
{
return cacheType;
}
_targetType = targetType;
CreateTypeBuilder(GenerateTypeName(targetType, interfaces), typeof(Object), interfaces);
GenerateFields();
ImplementGetObjectData(interfaces);
ImplementCacheInvocationCache();
GenerateInterfaceImplementation(interfaces);
GenerateConstructor();
return CreateType();
}
finally
{
rwlock.ReleaseWriterLock();
}
}
}