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); }
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); }
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); }
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); }
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; }
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; }
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; }
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); }
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); }
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); }
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); }
public static bool IsDefined <TAttribute>(this ICustomAttributeReflectorProvider customAttributeReflectorProvider) where TAttribute : Attribute { return(IsDefined(customAttributeReflectorProvider, typeof(TAttribute))); }
public static CustomAttributeReflector[] GetCustomAttributeReflectors(this ICustomAttributeReflectorProvider provider) { return(provider.CustomAttributeReflectors); }
public static TAttribute GetCustomAttribute <TAttribute>(this ICustomAttributeReflectorProvider customAttributeReflectorProvider) where TAttribute : Attribute { return((TAttribute)GetCustomAttribute(customAttributeReflectorProvider, typeof(TAttribute))); }
public static T GetCustomAttribute <T>(this ICustomAttributeReflectorProvider provider) where T : Attribute { return(provider.GetCustomAttribute(typeof(T)) as T); }
public static IEnumerable <Attribute> GetCustomAttributes(this ICustomAttributeReflectorProvider provider, Type attributeType) { return(provider.GetCustomAttributeReflectors(attributeType).Select(i => i.Invoke())); }
public static IEnumerable <T> GetCustomAttributes <T>(this ICustomAttributeReflectorProvider provider) where T : Attribute { return(provider.GetCustomAttributes(typeof(T)).Select(i => i as T)); }
public static bool IsDefined(this ICustomAttributeReflectorProvider provider, Type attributeType) { return(provider.GetCustomAttributeReflectors(attributeType).FirstOrDefault() != null); }
public static bool IsDefined <T>(this ICustomAttributeReflectorProvider provider) where T : Attribute { return(provider.IsDefined(typeof(T))); }
public static Attribute GetCustomAttribute(this ICustomAttributeReflectorProvider provider, Type attributeType) { return(provider.GetCustomAttributeReflectors(attributeType).Select(i => i.Invoke()).FirstOrDefault()); }
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))); } }
public static IEnumerable <T> GetCustomAttributesDistinctBy <T>(this ICustomAttributeReflectorProvider provider, params ICustomAttributeReflectorProvider[] providers) where T : Attribute { return(provider.Union(providers).GetCustomAttributesDistinctBy <T>()); }