Esempio n. 1
0
            public IInterceptorRegistry <TInterceptor> ToProperty <TTarget>(int order, Expression <Func <TTarget, object?> > propertyAccessor)
            {
                if (propertyAccessor == null)
                {
                    throw new ArgumentNullException(nameof(propertyAccessor));
                }
                var property = MemberUtilities.GetProperty(propertyAccessor);
                var method   = property.GetMethod;
                var valid    = false;

                if (method is not null && MemberUtilities.IsInterfaceOrVirtualMethod(method))
                {
                    ToMethods <TTarget>(order, method);
                    valid = true;
                }

                method = property.SetMethod;
                if (method is not null && MemberUtilities.IsInterfaceOrVirtualMethod(method))
                {
                    ToMethods <TTarget>(order, method);
                    valid = true;
                }

                if (!valid)
                {
                    throw new InterceptionException($"Interceptor is applied to the property '{property.Name}' of type '{typeof(TTarget)}', whose Get/Set methods are not virtual method or interface implementation method.");
                }

                return(this);
            }
Esempio n. 2
0
            public IInterceptorRegistry <TInterceptor> ToSetMethod <TTarget>(int order, Expression <Func <TTarget, object?> > propertyAccessor)
            {
                if (propertyAccessor == null)
                {
                    throw new ArgumentNullException(nameof(propertyAccessor));
                }
                var property  = MemberUtilities.GetProperty(propertyAccessor);
                var setMethod = property.SetMethod;

                if (setMethod is null)
                {
                    throw new InterceptionException($"Specified property '{property.Name}' of '{property.DeclaringType}' does not have Set method.");
                }
                return(ToMethods <TTarget>(order, setMethod));
            }