/// <summary> /// Creates a subclass proxy type /// </summary> /// <param name="type">Type to proxify</param> /// <returns>The proxy type</returns> public Type CreateProxyType(Type type) { lock (proxyLookup.SyncRoot) { Type proxyType = null; //incase a proxy for this type does not exist , generate it if (proxyLookup[type] == null) { IList typeAspects = AspectMatcher.MatchAspectsForType(type, Configuration.Aspects); IList typeMixins = GetMixinsForType(type, typeAspects); typeMixins.Add(typeof(AopProxyMixin)); #if NET2 if (SerializerIsAvailable()) { AddSerializerMixin(typeMixins); } #endif proxyType = SubclassProxyFactory.CreateProxyType(type, typeAspects, typeMixins, this); if (proxyType == null) { throw new NullReferenceException( string.Format("Could not generate proxy for type '{0}'", type.FullName)); } proxyLookup[type] = proxyType; string message = string.Format("Emitting new proxy type for type {0}", type.FullName); LogManager.Info(this, message, ""); } else { //fetch the proxy type from the lookup proxyType = proxyLookup[type] as Type; string message = string.Format("Fetching proxy type from cache for type {0}", type.FullName); LogManager.Info(this, message, ""); } return(proxyType); } }
private ProxyTypeInfo CreateProxyTypeInfo(Type type, bool useCtorState) { bool wasProxied = false; bool wasExtended = false; ProxyTypeInfo typeInfo = null; lock (proxyLookup.SyncRoot) { Type proxyType = null; //incase a proxy for this type does not exist , generate it if (proxyLookup[type] == null) { Type extendedType = type; IList typeAspects = AspectMatcher.MatchAspectsForType(type, Configuration.Aspects); IList typeMixins = GetMixinsForType(type, typeAspects); typeMixins.Add(typeof(AopProxyMixin)); #if NET2 if (SerializerIsAvailable()) { AddSerializerMixin(typeMixins); } #endif foreach (object aspect in typeAspects) { if (aspect is GenericAspectBase) { GenericAspectBase genericAspect = (GenericAspectBase)aspect; foreach (TypeExtender typeExtender in genericAspect.TypeExtenders) { wasExtended = true; extendedType = typeExtender.Extend(extendedType); } } } proxyType = SubclassProxyFactory.CreateProxyType(extendedType, typeAspects, typeMixins, this, useCtorState); if (proxyType == null) { throw new NullReferenceException( string.Format("Could not generate proxy for type '{0}'", type.FullName)); } if (proxyType != extendedType) { wasProxied = true; } typeInfo = new ProxyTypeInfo(); typeInfo.Type = proxyType; typeInfo.IsExtended = wasExtended; typeInfo.IsProxied = wasProxied; proxyLookup[type] = typeInfo; LogMessage message = new LogMessage("Emitting new proxy type for type {0}", type.FullName); LogManager.Info(this, message); } else { typeInfo = proxyLookup[type] as ProxyTypeInfo; //fetch the proxy type from the lookup proxyType = typeInfo.Type; LogMessage message = new LogMessage("Fetching proxy type from cache for type {0}", type.FullName); LogManager.Info(this, message); } return(typeInfo); } }