Example #1
0
        public ITargetPolicyBuilder <T> ExcludeProperty <TValue>(Expression <Func <T, TValue> > propertyAccessor, PropertyMethod propertyMethod)
        {
            Guard.ArgumentNotNull(propertyAccessor, nameof(propertyAccessor));
            var expression = propertyAccessor.Body as MemberExpression;

            if (null == expression)
            {
                throw new ArgumentException(Resources.NotPropertyAccessExpression, nameof(propertyAccessor));
            }
            var property = expression.Member as PropertyInfo;

            if (null == property)
            {
                throw new ArgumentException(Resources.NotPropertyAccessExpression, nameof(propertyAccessor));
            }
            _policy.ExcludedProperties[property.MetadataToken] = propertyMethod;
            return(this);
        }
Example #2
0
 public IInterceptorProvider[] GetInterceptorProvidersForProperty(Type targetType, PropertyInfo property, PropertyMethod propertyMethod)
 {
     Guard.ArgumentNotNull(property, nameof(property));
     if (propertyMethod == PropertyMethod.Get && property.GetMethod == null)
     {
         throw new ArgumentException(Resources.PropertyHasNoGetMethod.Fill(property.Name, property.DeclaringType.AssemblyQualifiedName), nameof(propertyMethod));
     }
     if (propertyMethod == PropertyMethod.Set && property.SetMethod == null)
     {
         throw new ArgumentException(Resources.PropertyHasNoSetMethod.Fill(property.Name, property.DeclaringType.AssemblyQualifiedName), nameof(propertyMethod));
     }
     return(_providerResolvers
            .SelectMany(it => it.GetInterceptorProvidersForProperty(targetType, property, propertyMethod))
            .ToArray());
 }
Example #3
0
        public ITargetPolicyBuilder <T> IncludeProperty <TValue>(Expression <Func <T, TValue> > propertyAccessor, PropertyMethod propertyMethod)
        {
            PropertyInfo property = GetProperty(propertyAccessor);

            _policy.IncludedProperties[property.MetadataToken] = propertyMethod;
            return(this);
        }
        public IInterceptorProvider[] GetInterceptorProvidersForProperty(Type targetType, PropertyInfo property, PropertyMethod propertyMethod)
        {
            Guard.ArgumentNotNull(nameof(property), nameof(property));
            var method = propertyMethod == PropertyMethod.Get ? property.GetMethod : property.SetMethod;

            return(CustomAttributeAccessor.GetCustomAttributes <IInterceptorProvider>(property).ToArray()
                   .Concat(CustomAttributeAccessor.GetCustomAttributes <IInterceptorProvider>(method).ToArray()));
        }
Example #5
0
        public IInterceptorProvider[] GetInterceptorProvidersForProperty(Type targetType, PropertyInfo property, PropertyMethod propertyMethod)
        {
            bool Filter(InterceptorProviderPolicy registration)
            {
                var target = registration.TargetPolicies.Where(it => it.TargetType == targetType).FirstOrDefault();

                //is explicitly excluded.
                if (target == null || (target.ExcludedProperties.TryGetValue(property.MetadataToken, out var methodType) && (methodType == propertyMethod || methodType == PropertyMethod.Both)))
                {
                    return(false);
                }

                //is explicitly included.
                if (target.IncludedProperties.TryGetValue(property.MetadataToken, out methodType) && (methodType == propertyMethod || methodType == PropertyMethod.Both))
                {
                    return(true);
                }

                //Incldue all members
                if (target.IncludeAllMembers == true)
                {
                    return(true);
                }

                return(false);
            }

            return((from it in _policy
                    where Filter(it)
                    select it.InterceptorProviderFactory())
                   .ToArray());
        }
Example #6
0
        public IInterceptorProvider[] GetInterceptorProvidersForProperty(Type targetType, PropertyInfo property, PropertyMethod propertyMethod, out ISet <Type> excludedInterceptorProviders)
        {
            Guard.ArgumentNotNull(property, nameof(property));
            if (propertyMethod == PropertyMethod.Get && property.GetMethod == null)
            {
                throw new ArgumentException(Resources.PropertyHasNoGetMethod.Fill(property.Name, property.DeclaringType.AssemblyQualifiedName), nameof(propertyMethod));
            }
            if (propertyMethod == PropertyMethod.Set && property.SetMethod == null)
            {
                throw new ArgumentException(Resources.PropertyHasNoSetMethod.Fill(property.Name, property.DeclaringType.AssemblyQualifiedName), nameof(propertyMethod));
            }

            var providers = new List <IInterceptorProvider>();
            var execluded = new List <Type>();

            for (int index = 0; index < _providerResolvers.Length; index++)
            {
                var resolver = _providerResolvers[index];
                providers.AddRange(resolver.GetInterceptorProvidersForProperty(targetType, property, propertyMethod, out var excludedProviders));
                execluded.AddRange(excludedProviders);
            }

            excludedInterceptorProviders = new HashSet <Type>(execluded);
            return(providers.ToArray());
        }
Example #7
0
    public IInterceptorProvider[] GetInterceptorProvidersForProperty(Type targetType, PropertyInfo targetProperty, PropertyMethod getOrSet)
    {
        switch (getOrSet)
        {
        case PropertyMethod.Get:
            return(GetInterceptorProvidersForMethod(targetType, targetProperty.GetMethod));

        case PropertyMethod.Set:
            return(GetInterceptorProvidersForMethod(targetType, targetProperty.SetMethod));

        default:
            return(GetInterceptorProvidersForMethod(targetType, targetProperty.GetMethod)
                   .Union(GetInterceptorProvidersForMethod(targetType, targetProperty.SetMethod))
                   .ToArray());
        }
    }
Example #8
0
        public IInterceptorProvider[] GetInterceptorProvidersForProperty(Type targetType, PropertyInfo property, PropertyMethod propertyMethod, out ISet <Type> excludedInterceptorProviders)
        {
            Guard.ArgumentNotNull(nameof(property), nameof(property));
            var method = propertyMethod == PropertyMethod.Get ? property.GetMethod : property.SetMethod;

            var list          = new List <Type>();
            var excludedTypes = CustomAttributeAccessor.GetCustomAttribute <NonInterceptableAttribute>(property)?.InterceptorProviderTypes;

            if (excludedTypes?.Length > 0)
            {
                list.AddRange(excludedTypes);
            }
            excludedTypes = CustomAttributeAccessor.GetCustomAttribute <NonInterceptableAttribute>(method)?.InterceptorProviderTypes;
            if (excludedTypes?.Length > 0)
            {
                list.AddRange(excludedTypes);
            }
            excludedInterceptorProviders = new HashSet <Type>(list);

            var providers = CustomAttributeAccessor.GetCustomAttributes <IInterceptorProvider>(property);

            providers.Concat(CustomAttributeAccessor.GetCustomAttributes <IInterceptorProvider>(method));
            return(providers.ToArray());
        }