public object Intercept(InvocationInfo info)
        {
            var methodName = info.TargetMethod.Name;

            if (FieldInterceptor != null)
            {
                if (ReflectHelper.IsPropertyGet(info.TargetMethod))
                {
                    if ("get_FieldInterceptor".Equals(methodName))
                    {
                        return(FieldInterceptor);
                    }

                    object propValue = info.InvokeMethodOnTarget();

                    var result = FieldInterceptor.Intercept(info.Target, ReflectHelper.GetPropertyName(info.TargetMethod), propValue);

                    if (result != AbstractFieldInterceptor.InvokeImplementation)
                    {
                        return(result);
                    }
                }
                else if (ReflectHelper.IsPropertySet(info.TargetMethod))
                {
                    if ("set_FieldInterceptor".Equals(methodName))
                    {
                        FieldInterceptor = (IFieldInterceptor)info.Arguments[0];
                        return(null);
                    }
                    FieldInterceptor.MarkDirty();
                    FieldInterceptor.Intercept(info.Target, ReflectHelper.GetPropertyName(info.TargetMethod), info.Arguments[0]);
                }
            }
            else
            {
                if ("set_FieldInterceptor".Equals(methodName))
                {
                    FieldInterceptor = (IFieldInterceptor)info.Arguments[0];
                    return(null);
                }
            }

            object returnValue;

            try
            {
                returnValue = info.InvokeMethodOnTarget();
            }
            catch (TargetInvocationException ex)
            {
                throw ReflectHelper.UnwrapTargetInvocationException(ex);
            }
            return(returnValue);
        }
Exemple #2
0
        public object Intercept(InvocationInfo info)
        {
            if (ReflectHelper.IsPropertyGet(info.TargetMethod))
            {
                if (IsGetFieldInterceptorCall(info.TargetMethod))
                {
                    return(FieldInterceptor);
                }

                if (FieldInterceptor != null)
                {
                    object propValue = info.InvokeMethodOnTarget();

                    var result = FieldInterceptor.Intercept(info.Target, ReflectHelper.GetPropertyName(info.TargetMethod), propValue);

                    if (result != AbstractFieldInterceptor.InvokeImplementation)
                    {
                        return(result);
                    }
                }
            }
            else if (ReflectHelper.IsPropertySet(info.TargetMethod))
            {
                if (IsSetFieldInterceptorCall(info.TargetMethod))
                {
                    FieldInterceptor = (IFieldInterceptor)info.Arguments[0];
                    return(null);
                }

                if (FieldInterceptor != null)
                {
                    FieldInterceptor.MarkDirty();
                    FieldInterceptor.Intercept(info.Target, ReflectHelper.GetPropertyName(info.TargetMethod), info.Arguments[0], true);
                }
            }

            return(info.InvokeMethodOnTarget());
        }
Exemple #3
0
 public object Intercept(InvocationInfo info)
 {
     //Do what you want
     return(info.InvokeMethodOnTarget());
 }