/// <summary> /// Creates a proxy type of a given type. /// </summary> /// <param name="baseType">Type to proxyfy</param> /// <param name="aspects">Untyped list of <c>IAspects</c> to apply to the proxy.</param> /// <param name="mixins">Untyped list of <c>System.Type</c>s that will be mixed in.</param> /// <param name="engine">The AopEngine requesting the proxy type</param> /// <returns></returns> public static Type CreateProxyType(Type baseType, IList aspects, IList mixins, Engine engine, bool useCtorState) { #if NET2 if (Engine.SerializerIsAvailable()) { if (aspects.Count == 0 && mixins.Count == 2 && !AopTools.HasFixedAttributes(baseType)) { return(baseType); } } else { if (aspects.Count == 0 && mixins.Count == 1 && !AopTools.HasFixedAttributes(baseType)) { return(baseType); } } #else if (aspects.Count == 0 && mixins.Count == 1 && !AopTools.HasFixedAttributes(baseType)) { return(baseType); } #endif SubclassProxyFactory factory = new SubclassProxyFactory(engine); return(factory.CreateType(baseType, aspects, mixins, useCtorState)); }
/// <summary> /// Creates a proxy type of a given type. /// </summary> /// <param name="baseType">Type to proxyfy</param> /// <param name="aspects">Untyped list of <c>IAspects</c> to apply to the proxy.</param> /// <param name="mixins">Untyped list of <c>System.Type</c>s that will be mixed in.</param> /// <param name="engine">The AopEngine requesting the proxy type</param> /// <returns></returns> public static Type CreateProxyType(Type baseType, IList aspects, IList mixins, Engine engine) { #if NET2 if (Engine.SerializerIsAvailable()) { if (aspects.Count == 0 && mixins.Count == 2) { return(baseType); } } else { if (aspects.Count == 0 && mixins.Count == 1) { return(baseType); } } #else if (aspects.Count == 0 && mixins.Count == 1) { return(baseType); } #endif SubclassProxyFactory factory = new SubclassProxyFactory(engine); return(factory.CreateType(baseType, aspects, mixins)); }
/// <summary> /// Creates a proxy type of a given type. /// </summary> /// <param name="baseType">Type to proxyfy</param> /// <param name="aspects">Untyped list of <c>IAspects</c> to apply to the proxy.</param> /// <param name="mixins">Untyped list of <c>System.Type</c>s that will be mixed in.</param> /// <param name="engine">The AopEngine requesting the proxy type</param> /// <returns></returns> public static Type CreateProxyType(Type baseType, IList aspects, IList mixins, Engine engine) { #if NET2 if (Engine.SerializerIsAvailable()) { if (aspects.Count == 0 && mixins.Count == 2) return baseType; } else { if (aspects.Count == 0 && mixins.Count == 1) return baseType; } #else if (aspects.Count == 0 && mixins.Count == 1) return baseType; #endif SubclassProxyFactory factory = new SubclassProxyFactory(engine); return factory.CreateType(baseType, aspects, mixins); }
/// <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); } }
/// <summary> /// Creates a proxy type of a given type. /// </summary> /// <param name="baseType">Type to proxyfy</param> /// <param name="aspects">Untyped list of <c>IAspects</c> to apply to the proxy.</param> /// <param name="mixins">Untyped list of <c>System.Type</c>s that will be mixed in.</param> /// <param name="engine">The AopEngine requesting the proxy type</param> /// <returns></returns> public static Type CreateProxyType(Type baseType, IList aspects, IList mixins, Engine engine, bool useCtorState) { #if NET2 if (Engine.SerializerIsAvailable()) { if (aspects.Count == 0 && mixins.Count == 2 && !AopTools.HasFixedAttributes(baseType)) return baseType; } else { if (aspects.Count == 0 && mixins.Count == 1 && !AopTools.HasFixedAttributes(baseType)) return baseType; } #else if (aspects.Count == 0 && mixins.Count == 1 && !AopTools.HasFixedAttributes(baseType)) return baseType; #endif SubclassProxyFactory factory = new SubclassProxyFactory(engine); return factory.CreateType(baseType, aspects, mixins,useCtorState); }
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); } }