private IList GetMixinsForType(Type type, IList typeAspects) { // IList typeAspects = AspectMatcher.MatchAspectsForType(type, Configuration.Aspects); Hashtable mixins = new Hashtable(); foreach (IAspect aspect in typeAspects) { IGenericAspect tmpAspect; if (aspect is IGenericAspect) { tmpAspect = (IGenericAspect)aspect; } else { tmpAspect = TypedToGenericConverter.Convert((ITypedAspect)aspect); } foreach (Type mixinType in tmpAspect.Mixins) { //distinct add mixin.. mixins[mixinType] = mixinType; } } foreach (FixedMixinAttribute fixedMixinAttribute in type.GetCustomAttributes(typeof(FixedMixinAttribute), true)) { foreach (Type mixinType in fixedMixinAttribute.Types) { mixins[mixinType] = mixinType; } } IList distinctMixins = new ArrayList(mixins.Values); LogMessage message = new LogMessage("Getting mixins for type {0}", type.FullName); string verbose = ""; foreach (Type mixinType in distinctMixins) { verbose += mixinType.Name; if (mixinType != distinctMixins[distinctMixins.Count - 1]) { verbose += ", "; } } LogManager.Info(this, message); return(distinctMixins); }
private void BuildLookupTables(Type proxyType, IList aspects, IList mixins) { MethodCache.methodsLookup[proxyType] = wrapperMethods; MethodCache.aspectsLookup[proxyType] = aspects; MethodCache.mixinsLookup[proxyType] = mixins; foreach (string methodId in wrapperMethods) { MethodInfo wrapperMethod = proxyType.GetMethod(methodId, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly); MethodCache.wrapperMethodLookup[methodId] = wrapperMethod; MethodBase baseMethod = (MethodBase)MethodCache.methodLookup[methodId]; //array to return IList methodinterceptors = new ArrayList(); //fetch all aspects from the type-aspect lookup foreach (IAspect aspect in aspects) { IGenericAspect tmpAspect; if (aspect is IGenericAspect) { tmpAspect = (IGenericAspect)aspect; } else { tmpAspect = TypedToGenericConverter.Convert((ITypedAspect)aspect); } foreach (IPointcut pointcut in tmpAspect.Pointcuts) { if (pointcut.IsMatch(baseMethod)) { foreach (object interceptor in pointcut.Interceptors) { methodinterceptors.Add(interceptor); } } } } MethodCache.methodInterceptorsLookup[methodId] = methodinterceptors; CallInfo callInfo = MethodCache.GetCallInfo(methodId); callInfo.Interceptors = methodinterceptors; } }
/// <summary> /// /// </summary> /// <returns></returns> public SerializedProxy GetSerializedProxy() { SerializedProxy proxy = new SerializedProxy(); VizType vizType = new VizType(); vizType.Name = target.GetType().Name; vizType.FullName = target.GetType().FullName; Type tmp = target.GetType(); while (typeof(IAopProxy).IsAssignableFrom(tmp)) { tmp = tmp.BaseType; } vizType.BaseName = tmp.Name; IList mixins = (IList)MethodCache.mixinsLookup[target.GetType()]; foreach (Type mixinType in mixins) { VizMixin vizMixin = new VizMixin(); vizMixin.TypeName = mixinType.Name; vizMixin.FullTypeName = mixinType.FullName; vizType.Mixins.Add(vizMixin); } IList aspects = (IList)MethodCache.aspectsLookup[target.GetType()]; foreach (IAspect aspect in aspects) { IGenericAspect tmpAspect; if (aspect is IGenericAspect) { tmpAspect = (IGenericAspect)aspect; } else { tmpAspect = TypedToGenericConverter.Convert((ITypedAspect)aspect); } VizAspect vizAspect = new VizAspect(); vizAspect.Name = tmpAspect.Name; } IList methods = (IList)MethodCache.methodsLookup[target.GetType()]; foreach (string methodId in methods) { MethodBase methodBase = (MethodBase)MethodCache.methodLookup[methodId]; if (methodBase is ConstructorInfo) { ConstructorInfo constructor = (ConstructorInfo)methodBase; VizConstructor vizConstructor = new VizConstructor(); vizConstructor.Name = constructor.Name; ParameterInfo[] paramInfos = constructor.GetParameters(); SerializeParameters(vizConstructor, paramInfos); IList interceptors = (IList)MethodCache.methodInterceptorsLookup[methodId]; SerializeInterceptors(vizConstructor, interceptors); vizConstructor.OwnerType = vizType; vizType.Methods.Add(vizConstructor); } else if (methodBase is MethodInfo) { MethodInfo method = (MethodInfo)methodBase; VizMethod vizMethod = new VizMethod(); vizMethod.Name = method.Name; vizMethod.ReturnType = method.ReturnType.Name; ParameterInfo[] paramInfos = method.GetParameters(); SerializeParameters(vizMethod, paramInfos); IList interceptors = (IList)MethodCache.methodInterceptorsLookup[methodId]; SerializeInterceptors(vizMethod, interceptors); vizMethod.OwnerType = vizType; vizType.Methods.Add(vizMethod); } } proxy.ProxyType = vizType; return(proxy); }