示例#1
0
        List <AdviceModel> ProcessAdvice()
        {
            var environment = new Environment(_pointcutDefinitions);

            IEnumerable <AdviceModel> CompileAdvice
            (
                IEnumerable <PointcutExpression> definitions,
                Func <PointcutExpression, Func <MethodDefinition, bool>, AdviceModel> func
            ) =>
            definitions
            .Select(d =>
            {
                try
                {
                    var compiledFunc = Compiler.Compile(d, environment);
                    return(func(d, compiledFunc));
                }
                catch (WeavingException e)
                {
                    throw new WeavingException($"{e.Message}At {d.DefiningMethod.FullName}");
                }
            });

            var beforeResults = CompileAdvice(_beforeDefinitions, (expression, func) => new BeforeAdvice(expression.DefiningMethod, func));

            var aroundResults = CompileAdvice(_aroundDefinitions, (expression, func) => new AroundAdvice(expression.DefiningMethod, func));

            return(beforeResults.Concat(aroundResults)
                   .ToList());
        }
示例#2
0
 public Compiler(PointcutExpression expression, Environment environment) =>
 (_expression, _environment) = (expression, environment);