コード例 #1
0
        public static Attribute GetCustomAttribute(this ICustomAttributeReflectorProvider customAttributeReflectorProvider, Type attributeType)
        {
            if (customAttributeReflectorProvider == null)
            {
                throw new ArgumentNullException(nameof(customAttributeReflectorProvider));
            }
            if (attributeType == null)
            {
                throw new ArgumentNullException(nameof(attributeType));
            }
            var customAttributeReflectors = customAttributeReflectorProvider.CustomAttributeReflectors;
            var customAttributeLength     = customAttributeReflectors.Length;

            if (customAttributeLength == 0)
            {
                return(null);
            }
            var attrToken = attributeType.TypeHandle;

            for (var i = 0; i < customAttributeLength; i++)
            {
                var reflector = customAttributeReflectors[i];
                if (reflector._tokens.Contains(attrToken))
                {
                    return(customAttributeReflectors[i].Invoke());
                }
            }
            return(null);
        }
コード例 #2
0
        public static bool IsDefined(this ICustomAttributeReflectorProvider customAttributeReflectorProvider, Type attributeType)
        {
            if (customAttributeReflectorProvider == null)
            {
                throw new ArgumentNullException(nameof(customAttributeReflectorProvider));
            }
            if (attributeType == null)
            {
                throw new ArgumentNullException(nameof(attributeType));
            }
            var customAttributeReflectors = customAttributeReflectorProvider.CustomAttributeReflectors;
            var customAttributeLength     = customAttributeReflectors.Length;

            if (customAttributeLength == 0)
            {
                return(false);
            }
            var attrToken = attributeType.TypeHandle;

            for (var i = 0; i < customAttributeLength; i++)
            {
                if (customAttributeReflectors[i]._tokens.Contains(attrToken))
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #3
0
        public static TAttribute[] GetCustomAttributes <TAttribute>(this ICustomAttributeReflectorProvider customAttributeReflectorProvider)
            where TAttribute : Attribute
        {
            if (customAttributeReflectorProvider == null)
            {
                throw new ArgumentNullException(nameof(customAttributeReflectorProvider));
            }
            var customAttributeReflectors = customAttributeReflectorProvider.CustomAttributeReflectors;
            var customAttributeLength     = customAttributeReflectors.Length;

            if (customAttributeLength == 0)
            {
                return(new TAttribute[0]);
            }
            var checkedAttrs = new TAttribute[customAttributeLength];
            var @checked     = 0;
            var attrToken    = typeof(TAttribute).TypeHandle;

            for (var i = 0; i < customAttributeLength; i++)
            {
                var reflector = customAttributeReflectors[i];
                if (reflector._tokens.Contains(attrToken))
                {
                    checkedAttrs[@checked++] = (TAttribute)reflector.Invoke();
                }
            }
            if (customAttributeLength == @checked)
            {
                return(checkedAttrs);
            }
            var attrs = new TAttribute[@checked];

            Array.Copy(checkedAttrs, attrs, @checked);
            return(attrs);
        }
コード例 #4
0
        internal MemberValueContractImpl(ObjectMember member, Type declaringType)
        {
            _member             = member ?? throw new ArgumentNullException(nameof(member));
            _lazyCallingHandler = new Lazy <ObjectCallerBase>(() => SafeObjectHandleSwitcher.Switch(AlgorithmKind.Precision)(declaringType));

            DeclaringType = declaringType;
            MemberKind    = member.Kind;
            IsBasicType   = member.MemberType.IsBasicType();

            _reflectorProvider = member.MemberType.GetReflector();
            _attributes        = _reflectorProvider.GetCustomAttributes();
            IncludeAnnotations = HasValidationAnnotationDefined(_attributes);
        }
コード例 #5
0
        public VerifiableObjectContract(ICustomVerifiableObjectContractImpl contractImpl)
        {
            _verifiableObjectContractImpl = contractImpl ?? throw new ArgumentNullException(nameof(contractImpl));
            Type        = contractImpl.Type;
            ObjectKind  = contractImpl.ObjectKind;
            IsBasicType = contractImpl.IsBasicType;

            _memberContracts = contractImpl.GetMemberContractMap();
            _valueKeys       = _memberContracts.Keys.ToArray();

            _reflectorProvider        = null;
            _attributes               = Arrays.Empty <Attribute>();
            IncludeAnnotationsForType = false;
        }
コード例 #6
0
        public VerifiableMemberContract(ICustomVerifiableMemberContractImpl contractImpl)
        {
            _verifiableMemberContractImpl = contractImpl ?? throw new ArgumentNullException(nameof(contractImpl));
            DeclaringType = contractImpl.DeclaringType;
            MemberKind    = VerifiableMemberKind.CustomContract;
            IsBasicType   = contractImpl.IsBasicType;

            _propertyInfo = null;
            _fieldInfo    = null;

            _reflectorProvider = null;
            _attributes        = Arrays.Empty <Attribute>();
            IncludeAnnotations = contractImpl.IncludeAnnotations;
        }
コード例 #7
0
        public VerifiableMemberContract(Type declaringType)
        {
            _verifiableMemberContractImpl = null;
            DeclaringType = declaringType;
            MemberKind    = VerifiableMemberKind.Unknown;
            IsBasicType   = declaringType.IsBasicType();

            _propertyInfo = null;
            _fieldInfo    = null;

            _reflectorProvider = null;
            _attributes        = Arrays.Empty <Attribute>();
            IncludeAnnotations = false;
        }
コード例 #8
0
        public VerifiableMemberContract(Type declaringType, FieldInfo field)
        {
            _verifiableMemberContractImpl = null;
            DeclaringType = declaringType;
            MemberKind    = VerifiableMemberKind.Field;
            IsBasicType   = field.FieldType.IsBasicType();

            _propertyInfo = null;
            _fieldInfo    = field;

            _reflectorProvider = field.GetReflector();
            _attributes        = _reflectorProvider.GetCustomAttributes();
            IncludeAnnotations = HasValidationAnnotationDefined(_attributes);
        }
コード例 #9
0
        public VerifiableObjectContract(
            Type type,
            Dictionary <string, VerifiableMemberContract> memberContracts)
        {
            _verifiableObjectContractImpl = null;
            Type        = type ?? throw new ArgumentNullException(nameof(type));
            ObjectKind  = type.GetObjectKind();
            IsBasicType = ObjectKind == VerifiableObjectKind.BasicType;

            _memberContracts = memberContracts ?? throw new ArgumentNullException(nameof(memberContracts));
            _valueKeys       = _memberContracts.Keys.ToArray();

            _reflectorProvider        = Type.GetReflector();
            _attributes               = _reflectorProvider.GetCustomAttributes();
            IncludeAnnotationsForType = HasValidationAnnotationDefined(_attributes);
        }
コード例 #10
0
        public static Attribute[] GetCustomAttributes(this ICustomAttributeReflectorProvider customAttributeReflectorProvider)
        {
            if (customAttributeReflectorProvider == null)
            {
                throw new ArgumentNullException(nameof(customAttributeReflectorProvider));
            }
            var customAttributeReflectors = customAttributeReflectorProvider.CustomAttributeReflectors;
            var customAttributeLength     = customAttributeReflectors.Length;

            if (customAttributeLength == 0)
            {
                return(empty);
            }
            var attrs = new Attribute[customAttributeLength];

            for (var i = 0; i < customAttributeLength; i++)
            {
                attrs[i] = customAttributeReflectors[i].Invoke();
            }
            return(attrs);
        }
コード例 #11
0
        public static Attribute[] GetCustomAttributes(this ICustomAttributeReflectorProvider customAttributeReflectorProvider, Type attributeType)
        {
            if (customAttributeReflectorProvider == null)
            {
                throw new ArgumentNullException(nameof(customAttributeReflectorProvider));
            }
            if (attributeType == null)
            {
                throw new ArgumentNullException(nameof(attributeType));
            }
            var customAttributeReflectors = customAttributeReflectorProvider.CustomAttributeReflectors;
            var customAttributeLength     = customAttributeReflectors.Length;

            if (customAttributeLength == 0)
            {
                return(empty);
            }
            var checkedAttrs = new Attribute[customAttributeLength];
            var @checked     = 0;
            var attrToken    = attributeType.TypeHandle;

            for (var i = 0; i < customAttributeLength; i++)
            {
                var reflector = customAttributeReflectors[i];
                if (reflector._tokens.Contains(attrToken))
                {
                    checkedAttrs[@checked++] = reflector.Invoke();
                }
            }
            if (customAttributeLength == @checked)
            {
                return(checkedAttrs);
            }
            var attrs = new Attribute[@checked];

            Array.Copy(checkedAttrs, attrs, @checked);
            return(attrs);
        }
コード例 #12
0
 public static bool IsDefined <TAttribute>(this ICustomAttributeReflectorProvider customAttributeReflectorProvider) where TAttribute : Attribute
 {
     return(IsDefined(customAttributeReflectorProvider, typeof(TAttribute)));
 }
コード例 #13
0
ファイル: AttributeExtensions.cs プロジェクト: qkb/Norns.Urd
 public static CustomAttributeReflector[] GetCustomAttributeReflectors(this ICustomAttributeReflectorProvider provider)
 {
     return(provider.CustomAttributeReflectors);
 }
コード例 #14
0
 public static TAttribute GetCustomAttribute <TAttribute>(this ICustomAttributeReflectorProvider customAttributeReflectorProvider)
     where TAttribute : Attribute
 {
     return((TAttribute)GetCustomAttribute(customAttributeReflectorProvider, typeof(TAttribute)));
 }
コード例 #15
0
 public static T GetCustomAttribute <T>(this ICustomAttributeReflectorProvider provider) where T : Attribute
 {
     return(provider.GetCustomAttribute(typeof(T)) as T);
 }
コード例 #16
0
ファイル: AttributeExtensions.cs プロジェクト: qkb/Norns.Urd
 public static IEnumerable <Attribute> GetCustomAttributes(this ICustomAttributeReflectorProvider provider, Type attributeType)
 {
     return(provider.GetCustomAttributeReflectors(attributeType).Select(i => i.Invoke()));
 }
コード例 #17
0
ファイル: AttributeExtensions.cs プロジェクト: qkb/Norns.Urd
 public static IEnumerable <T> GetCustomAttributes <T>(this ICustomAttributeReflectorProvider provider) where T : Attribute
 {
     return(provider.GetCustomAttributes(typeof(T)).Select(i => i as T));
 }
コード例 #18
0
ファイル: AttributeExtensions.cs プロジェクト: qkb/Norns.Urd
 public static bool IsDefined(this ICustomAttributeReflectorProvider provider, Type attributeType)
 {
     return(provider.GetCustomAttributeReflectors(attributeType).FirstOrDefault() != null);
 }
コード例 #19
0
ファイル: AttributeExtensions.cs プロジェクト: qkb/Norns.Urd
 public static bool IsDefined <T>(this ICustomAttributeReflectorProvider provider) where T : Attribute
 {
     return(provider.IsDefined(typeof(T)));
 }
コード例 #20
0
 public static Attribute GetCustomAttribute(this ICustomAttributeReflectorProvider provider, Type attributeType)
 {
     return(provider.GetCustomAttributeReflectors(attributeType).Select(i => i.Invoke()).FirstOrDefault());
 }
コード例 #21
0
ファイル: AttributeExtensions.cs プロジェクト: qkb/Norns.Urd
        public static IEnumerable <CustomAttributeReflector> GetCustomAttributeReflectors(this ICustomAttributeReflectorProvider provider, Type attributeType)
        {
            var reflectors = provider.GetCustomAttributeReflectors();

            if (reflectors.Length == 0)
            {
                return(reflectors);
            }
            else
            {
                var attrToken = attributeType.TypeHandle;
                return(reflectors.Where(i => i.Tokens.Contains(attrToken)));
            }
        }
コード例 #22
0
 public static IEnumerable <T> GetCustomAttributesDistinctBy <T>(this ICustomAttributeReflectorProvider provider, params ICustomAttributeReflectorProvider[] providers) where T : Attribute
 {
     return(provider.Union(providers).GetCustomAttributesDistinctBy <T>());
 }