Beispiel #1
0
        public IAspectExpressionBuilder VisitLast(IAspectDefinition aspectDefinition, IArgumentsWeavingSettings argumentsWeavingSettings)
        {
            Func <IAspectExpression, IAspectExpression> expressionFactory = null;
            var methodAspectDefinition = aspectDefinition as IMethodAspectDefinition;

            if (lastAspect.IsInBinding)
            {
                if (topAspectInScopeDefinition.AspectType == AspectType.MethodInterceptionAspect)
                {
                    expressionFactory = expression => {
                        return(new BindingMethodAspectDecoratorExpression(methodAspectDefinition, argumentsWeavingSettings));
                    };
                }
                else if (topAspectInScopeDefinition.IsPropertyAspectDefinition())
                {
                    var propertyAspectDefinition = (IPropertyAspectDefinition)topAspectInScopeDefinition;

                    expressionFactory = expression => {
                        if (topAspectInScopeDefinition.IsGetPropertyAspectDefinition())
                        {
                            return(new BindingGetPropertyAspectDecoratorExpression(propertyAspectDefinition));
                        }

                        return(new BindingSetPropertyAspectDecoratorExpression(propertyAspectDefinition));
                    };
                }
                else if (topAspectInScopeDefinition.IsEventAspectDefinition())
                {
                    var eventAspectDefinition = (IEventAspectDefinition)topAspectInScopeDefinition;

                    if (topAspectInScopeDefinition.AspectType == AspectType.AddEventInterceptionAspect)
                    {
                        expressionFactory = expression => {
                            return(new BindingAddEventAspectDecoratorExpression(eventAspectDefinition));
                        };
                    }
                    else if (topAspectInScopeDefinition.AspectType == AspectType.RemoveEventInterceptionAspect)
                    {
                        expressionFactory = expression => {
                            return(new BindingRemoveEventAspectDecoratorExpression(eventAspectDefinition));
                        };
                    }
                    else
                    {
                        expressionFactory = expression => {
                            return(new BindingRaiseEventAspectDecoratorExpression(eventAspectDefinition));
                        };
                    }
                }
                else
                {
                    expressionFactory = expression => {
                        return(new MethodInvokerAspectExpression(methodAspectDefinition, argumentsWeavingSettings, (IMethodAspectDefinition)topAspectInScopeDefinition));
                    };
                }
            }
            else
            {
                expressionFactory = expression => {
                    return(new NestedMethodInvokerAspectExpression(argumentsWeavingSettings, (IMethodAspectDefinition)topAspectInScopeDefinition));
                };
            }

            return(new AspectNodeExpressionBuilder(expressionFactory));
        }