private ItemMetadata(ClassMetadata owner, ItemMemberKind memberKind, Type clrType, string name, ConfigurationItemAttribute attribute, IEnumerable<ValueValidatorAttribute> validators) { Owner = owner; MemberKind = memberKind; Name = name; Type = ItemType.GetItemType(clrType); UserDescription = attribute.UserDescription; Validators = new ReadOnlyCollection<ValueValidatorAttribute>(validators.ToArray()); if (attribute.UserName != null) { UserName = attribute.UserName; } else { UserName = Name; } VerifyDefaultValue(clrType, attribute.DefaultValue, Name); SerializedDefaultValue = new XElement(XName.Get("defaultValue")); #region In case of dictionary type, convert default array of keys and values into dictionary if ((Type is DictionaryItemType) && (attribute.DefaultValue != null)) { Dictionary<object, object> defaultDictionary = new Dictionary<object, object>(); Array defaultArray = (Array)attribute.DefaultValue; for (int i = 0; i < defaultArray.Length / 2; i++) { object key = defaultArray.GetValue((i * 2) + 0); object value = defaultArray.GetValue((i * 2) + 1); defaultDictionary.Add(key, value); } attribute.DefaultValue = defaultDictionary; } #endregion if (Type is CustomItemType) { CustomItemType customType = (CustomItemType)Type; customType.GetCustomType().WriteDefaultValueToXElement(SerializedDefaultValue, attribute.DefaultValue); } else { Type.WriteToXElement(SerializedDefaultValue, attribute.DefaultValue); } }
/// <summary> /// Constructs a metadata description for given property. /// </summary> /// <param name="owner">Metadata of owning class.</param> /// <param name="property">Property representing configurable item.</param> /// <param name="attribute">Attribute of configurable item attached to the property.</param> /// <param name="validators">Required validators for configuration item.</param> public ItemMetadata(ClassMetadata owner, PropertyInfo property, ConfigurationItemAttribute attribute, IEnumerable<ValueValidatorAttribute> validators) : this(owner, ItemMemberKind.Property, property.PropertyType, property.Name, attribute, validators) { }
/// <summary> /// Constructs a metadata description for given field. /// </summary> /// <param name="owner">Metadata of owning class.</param> /// <param name="field">Field representing configurable item.</param> /// <param name="attribute">Attribute of configurable item attached to the field.</param> /// <param name="validators">Required validators for configuration item.</param> public ItemMetadata(ClassMetadata owner, FieldInfo field, ConfigurationItemAttribute attribute, IEnumerable<ValueValidatorAttribute> validators) : this(owner, ItemMemberKind.Field, field.FieldType, field.Name, attribute, validators) { }