Exemplo n.º 1
0
        public void Intercept(IInvocation invocation)
        {
            invocation.Proceed();

            BaseNotifyPropertyChangedAttribute attribute = ProxyCommon.AsAttribute <BaseNotifyPropertyChangedAttribute>(invocation.Method);

            if (attribute != null)
            {
                BaseNotifyPropertyChanged @base = invocation.InvocationTarget as BaseNotifyPropertyChanged;

                foreach (string property in attribute.PropertiesToNotify)
                {
                    @base.OnPropertyChanged(property);
                }
            }
        }
        public override IMessage Invoke(IMessage msg)
        {
            IMethodCallMessage methodCall = msg as IMethodCallMessage;
            MethodInfo         methodInfo = methodCall.MethodBase as MethodInfo;

            try
            {
                // Always call the method
                Console.WriteLine(methodInfo.DeclaringType.FullName + "#" + methodInfo.Name);
                object result = methodInfo.Invoke(_decorated, methodCall.InArgs);

                // Check if it is a set with the BaseNotifyPropertyChangedAttribute and if it is call the OnPropertyChanged as well
                if (methodInfo.Name.StartsWith("set") && !methodInfo.CustomAttributes.Any
                    (
                        a => a.AttributeType == typeof(BaseNotifyPropertyChangedAttribute)
                    ))
                {
                    BaseNotifyPropertyChangedAttribute attribute = Attribute.GetCustomAttribute
                                                                   (
                        methodInfo,
                        typeof(BaseNotifyPropertyChangedAttribute)
                                                                   ) as BaseNotifyPropertyChangedAttribute;

                    foreach (string property in attribute.PropertiesToNotify)
                    {
                        _decorated.OnPropertyChanged(property);
                    }

                    //attribute.AfterNotifyCall(_decorated as GameSession);
                }

                return(new ReturnMessage(result, null, 0, methodCall.LogicalCallContext, methodCall));
            }
            catch (System.Exception e)
            {
                // N o t e: since this impl is on property setters and OnPropertyChanged there should never be an error.
                return(new ReturnMessage(e, methodCall));
            }
        }