public void Execute(AdviceSpec spec) { foreach (Navigator aspectNav in spec.AspectNavigators) { IMethodDefinition aspectMethod = Narrow.Interceptor(aspectNav, spec); foreach (Navigator targetNav in spec.TargetNavigators) { MethodDefinition targetMethod = Narrow.ConcreteMethod(targetNav, spec); // Prevent recursive weaving if (targetMethod != aspectMethod && !Cil.BelongsToAspectDng(targetMethod) && !Cil.BelongsToAspectDng(aspectMethod) && targetMethod.GenericParameters.Count == 0 && targetMethod.DeclaringType.GenericParameters.Count == 0) { // Cannot keep semantics of "ref" parameters if (targetMethod.ToString().IndexOf("&") == -1) { AddInterceptor(targetMethod, aspectMethod); } } } } }
public void Execute(AdviceSpec spec) { foreach (Navigator aspectNav in spec.AspectNavigators) { IMethodDefinition aspectMethod = Narrow.Interceptor(aspectNav, spec); foreach (Navigator targetNav in spec.TargetNavigators) { Instruction targetCallInstruction = Narrow.CallInstruction(targetNav, spec); MethodReference targetMethod = (MethodReference)targetCallInstruction.Operand; MethodDefinition containerMethod = Narrow.Method(targetNav.Parent, spec); // Prevent recursive weaving if (targetMethod != aspectMethod && containerMethod != aspectMethod && !Cil.BelongsToAspectDng(targetMethod) && !Cil.BelongsToAspectDng(aspectMethod) && !Cil.BelongsToAspectDng(containerMethod) && targetMethod.GenericParameters.Count == 0 && targetMethod.DeclaringType.GenericParameters.Count == 0) { // Cannot weave on acces to boxed arrays. Methods look like int32[0...,0...]::Get(int32, int32) if (targetMethod.DeclaringType.Name.IndexOf("]") == -1 && targetMethod.ToString().IndexOf("&") == -1 // To prevent base.SameMethod() calls from child types, event if AroundBody already occurred && Cil.GetOriginalMethodName(targetMethod) != Cil.GetOriginalMethodName(containerMethod) ) { AddInterceptor(targetCallInstruction, containerMethod, aspectMethod); } } } } }
public void Execute(AdviceSpec spec) { foreach (Navigator aspectNav in spec.AspectNavigators) { MethodDefinition aspectMethod = Narrow.Interceptor(aspectNav, spec); foreach (Navigator targetNav in spec.TargetNavigators) { Instruction targetCallInstruction = Narrow.Instruction(targetNav, spec); MethodDefinition targetMethod = Narrow.Method(targetNav.Parent, spec); // We don't want to intercept volatile field accessors (marshalling problem) string fieldTypeName = ((FieldReference)targetCallInstruction.Operand).FieldType.Name; if (fieldTypeName.IndexOf(typeof(System.Runtime.CompilerServices.IsVolatile).Name) == -1) { AddInterceptor(targetCallInstruction, targetMethod, aspectMethod); } } } }