public PointCut(ILProcessor processor, Instruction instruction) { Processor = processor; InjectionPoint = instruction; ModuleContext = ModuleContext.GetOrCreateContext(processor.Body.Method.Module); MethodContext = MethodContextFactory.GetOrCreateContext(processor.Body.Method); TypeSystem = ModuleContext.TypeSystem; }
private void ProcessAspectDefinitions(MethodDefinition targetMethod, string targetName, IEnumerable <AspectDefinition> aspectDefinitions) { var filteredDefinitions = aspectDefinitions.Where(def => CheckFilter(targetMethod, targetName, def)); var mergedDefinitions = MergeAspectDefinitions(filteredDefinitions); var contexts = mergedDefinitions .Select(def => { var adviceClassType = def.AdviceClassType; var aspectScope = targetMethod.IsStatic ? AspectScope.Type : AspectScope.Instance; if (adviceClassType.CustomAttributes.HasAttributeOfType <AspectScopeAttribute>()) { aspectScope = (AspectScope)adviceClassType.CustomAttributes.GetAttributeOfType <AspectScopeAttribute>().ConstructorArguments[0].Value; } var aspectContext = new AspectContext() { TargetName = targetName, TargetTypeContext = TypeContextFactory.GetOrCreateContext(targetMethod.DeclaringType), AdviceClassType = adviceClassType, AdviceClassScope = aspectScope, AspectRoutableData = def.RoutableData == null ? new CustomAttribute[] { } : def.RoutableData.ToArray() }; return(aspectContext); }) .Where(ctx => _processors.Any(p => p.CanProcess(ctx.AdviceClassType))) .ToList(); Validator.ValidateAspectContexts(contexts); foreach (var context in contexts) { var targetMethodContext = MethodContextFactory.GetOrCreateContext(targetMethod); context.TargetMethodContext = targetMethodContext; //setting it here for better performance foreach (var processor in _processors) { if (processor.CanProcess(context.AdviceClassType)) { processor.Process(context); } } } }