/// <summary> /// Retrieves the <see cref="DisplayAttribute"/> associated with the given type. It may be null. /// </summary> /// <param name="validationContext">The context that describes the type. It cannot be null.</param> /// <returns>The display attribute instance, if present.</returns> internal DisplayAttribute GetTypeDisplayAttribute(ValidationContext validationContext) { EnsureValidationContext(validationContext); TypeStoreItem item = this.GetTypeStoreItem(validationContext.ObjectType); return(item.DisplayAttribute); }
/// <summary> /// Retrieves the type level validation attributes for the given type. /// </summary> /// <param name="validationContext">The context that describes the type. It cannot be null.</param> /// <returns>The collection of validation attributes. It could be empty.</returns> internal IEnumerable <ValidationAttribute> GetTypeValidationAttributes(ValidationContext validationContext) { EnsureValidationContext(validationContext); TypeStoreItem item = this.GetTypeStoreItem(validationContext.ObjectType); return(item.ValidationAttributes); }
/// <summary> /// Determines whether or not a given <see cref="ValidationContext"/>'s /// <see cref="ValidationContext.MemberName"/> references a property on /// the <see cref="ValidationContext.ObjectType"/>. /// </summary> /// <param name="validationContext">The <see cref="ValidationContext"/> to check.</param> /// <returns><c>true</c> when the <paramref name="validationContext"/> represents a property, <c>false</c> otherwise.</returns> internal bool IsPropertyContext(ValidationContext validationContext) { EnsureValidationContext(validationContext); TypeStoreItem typeItem = this.GetTypeStoreItem(validationContext.ObjectType); PropertyStoreItem item = null; return(typeItem.TryGetPropertyStoreItem(validationContext.MemberName, out item)); }
/// <summary> /// Retrieves the set of validation attributes for the property /// </summary> /// <param name="validationContext">The context that describes the property. It cannot be null.</param> /// <returns>The collection of validation attributes. It could be empty.</returns> internal IEnumerable <ValidationAttribute> GetPropertyValidationAttributes(ValidationContext validationContext) { EnsureValidationContext(validationContext); TypeStoreItem typeItem = this.GetTypeStoreItem(validationContext.ObjectType); PropertyStoreItem item = typeItem.GetPropertyStoreItem(validationContext.MemberName); return(item.ValidationAttributes); }
/// <summary> /// Retrieves the <see cref="DisplayAttribute"/> associated with the given property /// </summary> /// <param name="validationContext">The context that describes the property. It cannot be null.</param> /// <returns>The display attribute instance, if present.</returns> internal DisplayAttribute GetPropertyDisplayAttribute(ValidationContext validationContext) { EnsureValidationContext(validationContext); TypeStoreItem typeItem = this.GetTypeStoreItem(validationContext.ObjectType); PropertyStoreItem item = typeItem.GetPropertyStoreItem(validationContext.MemberName); return(item.DisplayAttribute); }
/// <summary> /// Retrieves the Type of the given property. /// </summary> /// <param name="validationContext">The context that describes the property. It cannot be null.</param> /// <returns>The type of the specified property</returns> internal Type GetPropertyType(ValidationContext validationContext) { EnsureValidationContext(validationContext); TypeStoreItem typeItem = this.GetTypeStoreItem(validationContext.ObjectType); PropertyStoreItem item = typeItem.GetPropertyStoreItem(validationContext.MemberName); return(item.PropertyType); }
/// <summary> /// Retrieves or creates the store item for the given type. /// </summary> /// <param name="type">The type whose store item is needed.</param> /// <returns>The type store item. It will not be <c>null</c>.</returns> private TypeStoreItem GetTypeStoreItem(Type type) { Debug.Assert(type != null); lock (_typeStoreItems) { if (!_typeStoreItems.TryGetValue(type, out TypeStoreItem item)) { // Use CustomAttributeExtensions.GetCustomAttributes() to get inherited attributes as well as direct ones var attributes = CustomAttributeExtensions.GetCustomAttributes(type.GetTypeInfo(), true); _typeStoreItems[type] = item = new TypeStoreItem(type, attributes); } return(item); } }
/// <summary> /// Retrieves or creates the store item for the given type /// </summary> /// <param name="type">The type whose store item is needed. It cannot be null</param> /// <returns>The type store item. It will not be null.</returns> private TypeStoreItem GetTypeStoreItem([DynamicallyAccessedMembers(TypeStoreItem.DynamicallyAccessedTypes)] Type type) { Debug.Assert(type != null); lock (_typeStoreItems) { if (!_typeStoreItems.TryGetValue(type, out TypeStoreItem? item)) { AttributeCollection attributes = TypeDescriptor.GetAttributes(type); item = new TypeStoreItem(type, attributes); _typeStoreItems[type] = item; } return(item); } }
/// <summary> /// Retrieves or creates the store item for the given type. /// </summary> /// <param name="type">The type whose store item is needed. It cannot be null.</param> /// <returns>The type store item. It will not be null.</returns> private TypeStoreItem GetTypeStoreItem(Type type) { lock (typeStoreItems) { if (typeStoreItems.TryGetValue(type, out var item)) { return(item); } // use CustomAttributeExtensions.GetCustomAttributes() to get inherited attributes as well as direct ones var attributes = CustomAttributeExtensions.GetCustomAttributes(type, true).ToArray(); item = new TypeStoreItem(type, attributes); typeStoreItems[type] = item; return(item); } }
/// <summary> /// Retrieves or creates the store item for the given type /// </summary> /// <param name="type">The type whose store item is needed. It cannot be null</param> /// <returns>The type store item. It will not be null.</returns> private TypeStoreItem GetTypeStoreItem([DynamicallyAccessedMembers(TypeStoreItem.DynamicallyAccessedTypes)] Type type) { Debug.Assert(type != null); lock (_typeStoreItems) { if (!_typeStoreItems.TryGetValue(type, out TypeStoreItem? item)) { // use CustomAttributeExtensions.GetCustomAttributes() to get inherited attributes as well as direct ones var attributes = CustomAttributeExtensions.GetCustomAttributes(type, true); item = new TypeStoreItem(type, attributes); _typeStoreItems[type] = item; } return(item); } }
/// <summary> /// Retrieves or creates the store item for the given type /// </summary> /// <param name="type">The type whose store item is needed. It cannot be null</param> /// <returns>The type store item. It will not be null.</returns> private TypeStoreItem GetTypeStoreItem(Type type) { if (type == null) { throw new ArgumentNullException("type"); } TypeStoreItem item = null; if (!this._typeStoreItems.TryGetValue(type, out item)) { IEnumerable <Attribute> attributes = type.GetCustomAttributes(true).Cast <Attribute>(); item = new TypeStoreItem(type, attributes); this._typeStoreItems[type] = item; } return(item); }
/// <summary> /// Retrieves or creates the store item for the given type /// </summary> /// <param name="type">The type whose store item is needed. It cannot be null</param> /// <returns>The type store item. It will not be null.</returns> private TypeStoreItem GetTypeStoreItem(Type type) { if (type == null) { throw new ArgumentNullException("type"); } lock (_typeStoreItems) { TypeStoreItem item = null; if (!_typeStoreItems.TryGetValue(type, out item)) { // use CustomAttributeExtensions.GetCustomAttributes() to get inherited attributes as well as direct ones var attributes = CustomAttributeExtensions.GetCustomAttributes(type.GetTypeInfo(), true); item = new TypeStoreItem(type, attributes); _typeStoreItems[type] = item; } return(item); } }
private TypeStoreItem GetTypeStoreItem(Type type) { if (type == null) { throw new ArgumentNullException("type"); } lock (this._typeStoreItems) { TypeStoreItem item = null; if (!this._typeStoreItems.TryGetValue(type, out item)) { IEnumerable <Attribute> attributes = System.ComponentModel.TypeDescriptor.GetAttributes(type).Cast <Attribute>(); item = new TypeStoreItem(type, attributes); this._typeStoreItems[type] = item; } return(item); } }
/// <summary> /// Retrieves or creates the store item for the given type /// </summary> /// <param name="type">The type whose store item is needed. It cannot be null</param> /// <returns>The type store item. It will not be null.</returns> private TypeStoreItem GetTypeStoreItem(Type type) { if (type == null) { throw new ArgumentNullException("type"); } lock (this._typeStoreItems) { TypeStoreItem item = null; if (!this._typeStoreItems.TryGetValue(type, out item)) { IEnumerable <Attribute> attributes = #if SILVERLIGHT type.GetCustomAttributes(true).Cast <Attribute>(); #else TypeDescriptor.GetAttributes(type).Cast <Attribute>(); #endif item = new TypeStoreItem(type, attributes); this._typeStoreItems[type] = item; } return(item); } }
/// <summary> /// Retrieves or creates the store item for the given type /// </summary> /// <param name="type">The type whose store item is needed. It cannot be null</param> /// <returns>The type store item. It will not be null.</returns> private TypeStoreItem GetTypeStoreItem(Type type) { if (type == null) { throw new ArgumentNullException("type"); } TypeStoreItem item = null; if (!this._typeStoreItems.TryGetValue(type, out item)) { IEnumerable<Attribute> attributes = type.GetCustomAttributes(true).Cast<Attribute>(); item = new TypeStoreItem(type, attributes); this._typeStoreItems[type] = item; } return item; }
private ValidationAttributeStore.TypeStoreItem GetTypeStoreItem( Type type ) { if ( type == null ) throw new ArgumentNullException( "type" ); TypeStoreItem result; lock ( typeStoreItems ) { TypeStoreItem typeStoreItem = null; if ( !typeStoreItems.TryGetValue( type, out typeStoreItem ) ) { var attributes = type.GetTypeInfo().GetCustomAttributes<Attribute>(); typeStoreItem = new TypeStoreItem( type, attributes ); typeStoreItems[type] = typeStoreItem; } result = typeStoreItem; } return result; }
/// <summary> /// Retrieves or creates the store item for the given type /// </summary> /// <param name="type">The type whose store item is needed. It cannot be null</param> /// <returns>The type store item. It will not be null.</returns> private TypeStoreItem GetTypeStoreItem(Type type) { if (type == null) { throw new ArgumentNullException(nameof(type)); } lock (_typeStoreItems) { TypeStoreItem item = null; if (!_typeStoreItems.TryGetValue(type, out item)) { // use CustomAttributeExtensions.GetCustomAttributes() to get inherited attributes as well as direct ones var attributes = CustomAttributeExtensions.GetCustomAttributes(type.GetTypeInfo(), true); item = new TypeStoreItem(type, attributes); _typeStoreItems[type] = item; } return item; } }
/// <summary> /// Retrieves or creates the store item for the given type /// </summary> /// <param name="type">The type whose store item is needed. It cannot be null</param> /// <returns>The type store item. It will not be null.</returns> private TypeStoreItem GetTypeStoreItem(Type type) { Debug.Assert(type != null); lock (_typeStoreItems) { TypeStoreItem item = null; if (!_typeStoreItems.TryGetValue(type, out item)) { // use CustomAttributeExtensions.GetCustomAttributes() to get inherited attributes as well as direct ones var attributes = CustomAttributeExtensions.GetCustomAttributes(type.GetTypeInfo(), true); item = new TypeStoreItem(type, attributes); _typeStoreItems[type] = item; } return item; } }
/// <summary> /// Retrieves or creates the store item for the given type /// </summary> /// <param name="type">The type whose store item is needed. It cannot be null</param> /// <returns>The type store item. It will not be null.</returns> private TypeStoreItem GetTypeStoreItem(Type type) { if (type == null) { throw new ArgumentNullException("type"); } lock (this._typeStoreItems) { TypeStoreItem item = null; if (!this._typeStoreItems.TryGetValue(type, out item)) { IEnumerable<Attribute> attributes = #if SILVERLIGHT type.GetCustomAttributes(true).Cast<Attribute>(); #else TypeDescriptor.GetAttributes(type).Cast<Attribute>(); #endif item = new TypeStoreItem(type, attributes); this._typeStoreItems[type] = item; } return item; } }