/// <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 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 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> /// 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)); }
internal PropertyStoreItem GetPropertyStoreItem(string propertyName) { PropertyStoreItem item = null; if (!this.TryGetPropertyStoreItem(propertyName, out item)) { throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, DataAnnotationsResources.AttributeStore_Unknown_Property, this._type.Name, propertyName), "propertyName"); } return(item); }
internal PropertyStoreItem GetPropertyStoreItem(string propertyName) { PropertyStoreItem item = null; if (!this.TryGetPropertyStoreItem(propertyName, out item)) { throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, "Unknown property {0} {1}", this._type.Name, propertyName), "propertyName"); } return(item); }
internal PropertyStoreItem GetPropertyStoreItem(string propertyName) { PropertyStoreItem item = null; if (!TryGetPropertyStoreItem(propertyName, out item)) { throw new ArgumentException("propertyName"); } return(item); }
internal PropertyStoreItem GetPropertyStoreItem(string propertyName) { PropertyStoreItem item = null; if (!TryGetPropertyStoreItem(propertyName, out item)) { throw new ArgumentException( string.Format(CultureInfo.CurrentCulture, SR.AttributeStore_Unknown_Property, _type.Name, propertyName), nameof(propertyName)); } return(item); }
private Dictionary <string, PropertyStoreItem> CreatePropertyStoreItems() { Dictionary <string, PropertyStoreItem> propertyStoreItems = new Dictionary <string, PropertyStoreItem>(); System.ComponentModel.PropertyDescriptorCollection properties = System.ComponentModel.TypeDescriptor.GetProperties(this._type); foreach (System.ComponentModel.PropertyDescriptor property in properties) { PropertyStoreItem item = new PropertyStoreItem(property.PropertyType, GetExplicitAttributes(property).Cast <Attribute>()); propertyStoreItems[property.Name] = item; } return(propertyStoreItems); }
private Dictionary <string, PropertyStoreItem> CreatePropertyStoreItems() { Dictionary <string, PropertyStoreItem> propertyStoreItems = new Dictionary <string, PropertyStoreItem>(); PropertyInfo[] properties = this._type.GetProperties(); foreach (PropertyInfo property in properties) { PropertyStoreItem item = new PropertyStoreItem(property.PropertyType, property.GetCustomAttributes(true).Cast <Attribute>()); propertyStoreItems[property.Name] = item; } return(propertyStoreItems); }
private Dictionary <string, PropertyStoreItem> CreatePropertyStoreItems() { var propertyStoreItems = new Dictionary <string, PropertyStoreItem>(); var properties = TypeDescriptor.GetProperties(_type); foreach (PropertyDescriptor property in properties) { var item = new PropertyStoreItem(property.PropertyType, GetExplicitAttributes(property)); propertyStoreItems[property.Name] = item; } return(propertyStoreItems); }
internal bool TryGetPropertyStoreItem( string propertyName, out PropertyStoreItem item ) { if ( string.IsNullOrEmpty( propertyName ) ) throw new ArgumentNullException( "propertyName" ); if ( propertyStoreItems == null ) { lock ( syncRoot ) { if ( propertyStoreItems == null ) propertyStoreItems = CreatePropertyStoreItems(); } } return propertyStoreItems.TryGetValue( propertyName, out item ); }
/// <summary> /// Creates and stores <see cref="PropertyStoreItem" />s. /// </summary> /// <returns>The dictionary of <see cref="PropertyStoreItem"/> associated by property name.</returns> private Dictionary <string, PropertyStoreItem> CreatePropertyStoreItems() { var propertyStoreItems = new Dictionary <string, PropertyStoreItem>(); // exclude index properties to match old TypeDescriptor functionality var properties = _type.GetRuntimeProperties().Where(prop => IsPublic(prop) && !prop.GetIndexParameters().Any()); foreach (PropertyInfo property in properties) { // use CustomAttributeExtensions.GetCustomAttributes() to get inherited attributes as well as direct ones var item = new PropertyStoreItem(property.PropertyType, CustomAttributeExtensions.GetCustomAttributes(property, true)); propertyStoreItems[property.Name] = item; } return(propertyStoreItems); }
private void CreatePropertyStoreItems() { #if SILVERLIGHT PropertyInfo[] properties = this._type.GetProperties(); foreach (PropertyInfo property in properties) { PropertyStoreItem item = new PropertyStoreItem(property.PropertyType, property.GetCustomAttributes(true).Cast <Attribute>()); this._propertyStoreItems[property.Name] = item; } #else PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(this._type); foreach (PropertyDescriptor property in properties) { PropertyStoreItem item = new PropertyStoreItem(property.PropertyType, GetExplicitAttributes(property).Cast <Attribute>()); this._propertyStoreItems[property.Name] = item; } #endif // SILVERLIGHT }
/// <summary> /// Determines if a <see cref="PropertyStoreItem" /> exists for the specified property name. /// </summary> /// <param name="propertyName">The property name to lookup.</param> /// <param name="item">The <see cref="PropertyStoreItem" /> that was found.</param> /// <returns><c>true</c> if a <see cref="PropertyStoreItem" /> is found for the specified property name, otherwise, <c>false</c>.</returns> internal bool TryGetPropertyStoreItem(string propertyName, out PropertyStoreItem item) { if (String.IsNullOrEmpty(propertyName)) { throw new ArgumentNullException(nameof(propertyName)); } if (_propertyStoreItems == null) { lock (_syncRoot) { if (_propertyStoreItems == null) { _propertyStoreItems = CreatePropertyStoreItems(); } } } return(_propertyStoreItems.TryGetValue(propertyName, out item)); }
internal bool TryGetPropertyStoreItem(string propertyName, out PropertyStoreItem item) { if (string.IsNullOrEmpty(propertyName)) { throw new ArgumentNullException("propertyName"); } if (this._propertyStoreItems == null) { if (this._propertyStoreItems == null) { this._propertyStoreItems = this.CreatePropertyStoreItems(); } } if (!this._propertyStoreItems.TryGetValue(propertyName, out item)) { return(false); } return(true); }
private Dictionary <string, PropertyStoreItem> CreatePropertyStoreItems() { Dictionary <string, PropertyStoreItem> propertyStoreItems = new Dictionary <string, PropertyStoreItem>(); #if SILVERLIGHT PropertyInfo[] properties = this._type.GetProperties(); foreach (PropertyInfo property in properties) { PropertyStoreItem item = new PropertyStoreItem(property.PropertyType, property.GetCustomAttributes(true).Cast <Attribute>()); propertyStoreItems[property.Name] = item; } #else PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(this._type); foreach (PropertyDescriptor property in properties) { PropertyStoreItem item = new PropertyStoreItem(property.PropertyType, GetExplicitAttributes(property).Cast <Attribute>()); propertyStoreItems[property.Name] = item; } #endif // SILVERLIGHT return(propertyStoreItems); }
private RadPropertyStore CreatePropertyStore() { RadPropertyStore vehicleStore = new RadPropertyStore(); PropertyStoreItem engineLayout = new PropertyStoreItem(typeof(EngineLayouts), "Layout", EngineLayouts.I4, "Engine layout is determined by the configuration of the engine pistons.", "Engine"); PropertyStoreItem engineDisplacement = new PropertyStoreItem(typeof(int), "Displacement", 1600, "Engine displacement is determined from the bore and stroke of the engine's cylinders.", "Engine"); PropertyStoreItem engineFuel = new PropertyStoreItem(typeof(Fuels), "Fuel", Fuels.Petrol, "The type of fuel providing the energy source for the engine.", "Engine"); PropertyStoreItem engineSupercharged = new PropertyStoreItem(typeof(bool), "Turbocharged/Supercharged", true, "Turbocharging/Supercharging is the process of compressing air on the intake of an engine(technical term - Forced induction).", "Engine"); PropertyStoreItem transmission = new PropertyStoreItem(typeof(Transmissions), "Transmission", Transmissions.SemiAutomatic, "The type of transmission thet would convert the engine power/torque.", "Drivetrain"); PropertyStoreItem drive = new PropertyStoreItem(typeof(Drives), "Drive", Drives.AllWheelDrive, "The configuration of the driving wheels.", "Drivetrain"); PropertyStoreItem vehicleSeats = new PropertyStoreItem(typeof(int), "Number of seats", 2, "The number of seats in the vehicle.", "Other"); PropertyStoreItem vehicleWeight = new PropertyStoreItem(typeof(int), "Weight", 1250, "The minimum wight of the car.", "Other"); vehicleStore.Add(engineLayout); vehicleStore.Add(engineDisplacement); vehicleStore.Add(engineFuel); vehicleStore.Add(engineSupercharged); vehicleStore.Add(transmission); vehicleStore.Add(drive); vehicleStore.Add(vehicleSeats); vehicleStore.Add(vehicleWeight); return(vehicleStore); }
private Dictionary<string, PropertyStoreItem> CreatePropertyStoreItems() { Dictionary<string, PropertyStoreItem> propertyStoreItems = new Dictionary<string, PropertyStoreItem>(); PropertyInfo[] properties = this._type.GetProperties(); foreach (PropertyInfo property in properties) { PropertyStoreItem item = new PropertyStoreItem(property.PropertyType, property.GetCustomAttributes(true).Cast<Attribute>()); propertyStoreItems[property.Name] = item; } return propertyStoreItems; }
public PropertyStoreItemValueChangedEventArgs(PropertyStoreItem item) { this.item = item; }
internal bool TryGetPropertyStoreItem(string propertyName, out PropertyStoreItem item) { if (string.IsNullOrEmpty(propertyName)) { throw new ArgumentNullException("propertyName"); } if (this._propertyStoreItems == null) { lock (this._syncRoot) { if (this._propertyStoreItems == null) { this._propertyStoreItems = new Dictionary<string, PropertyStoreItem>(); this.CreatePropertyStoreItems(); } } } if (!this._propertyStoreItems.TryGetValue(propertyName, out item)) { return false; } return true; }
private Dictionary<string, PropertyStoreItem> CreatePropertyStoreItems() { var propertyStoreItems = new Dictionary<string, PropertyStoreItem>(); // exclude index properties to match old TypeDescriptor functionality var properties = _type.GetRuntimeProperties() .Where(prop => IsPublic(prop) && !prop.GetIndexParameters().Any()); foreach (PropertyInfo property in properties) { // use CustomAttributeExtensions.GetCustomAttributes() to get inherited attributes as well as direct ones var item = new PropertyStoreItem(property.PropertyType, CustomAttributeExtensions.GetCustomAttributes(property, true)); propertyStoreItems[property.Name] = item; } return propertyStoreItems; }
private void CreatePropertyStoreItems() { #if SILVERLIGHT PropertyInfo[] properties = this._type.GetProperties(); foreach (PropertyInfo property in properties) { PropertyStoreItem item = new PropertyStoreItem(property.PropertyType, property.GetCustomAttributes(true).Cast<Attribute>()); this._propertyStoreItems[property.Name] = item; } #else PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(this._type); foreach (PropertyDescriptor property in properties) { PropertyStoreItem item = new PropertyStoreItem(property.PropertyType, GetExplicitAttributes(property).Cast<Attribute>()); this._propertyStoreItems[property.Name] = item; } #endif // SILVERLIGHT }