PropertyInformation
Contains meta-information on an individual property within the configuration. This type cannot be inherited.
using System.ComponentModel;
namespace System.Configuration
{
public sealed class PropertyInformation
{
private const string LockAll = "*";
private ConfigurationProperty _prop;
private readonly ConfigurationElement _thisElement;
private ConfigurationProperty Prop => _prop ?? (_prop = _thisElement.Properties[Name]);
public string Name { get; }
internal string ProvidedName => Prop.ProvidedName;
public object Value {
get {
return _thisElement[Name];
}
set {
_thisElement[Name] = value;
}
}
public object DefaultValue => Prop.DefaultValue;
public PropertyValueOrigin ValueOrigin {
get {
if (_thisElement.Values[Name] == null)
return PropertyValueOrigin.Default;
if (!_thisElement.Values.IsInherited(Name))
return PropertyValueOrigin.SetHere;
return PropertyValueOrigin.Inherited;
}
}
public bool IsModified {
get {
if (_thisElement.Values[Name] != null)
return _thisElement.Values.IsModified(Name);
return false;
}
}
public bool IsKey => Prop.IsKey;
public bool IsRequired => Prop.IsRequired;
public bool IsLocked {
get {
if ((_thisElement.LockedAllExceptAttributesList == null || _thisElement.LockedAllExceptAttributesList.DefinedInParent(Name)) && (_thisElement.LockedAttributesList == null || (!_thisElement.LockedAttributesList.DefinedInParent(Name) && !_thisElement.LockedAttributesList.DefinedInParent("*")))) {
if ((_thisElement.ItemLocked & ConfigurationValueFlags.Locked) != 0)
return (_thisElement.ItemLocked & ConfigurationValueFlags.Inherited) != ConfigurationValueFlags.Default;
return false;
}
return true;
}
}
public string Source {
get {
PropertySourceInfo propertySourceInfo = _thisElement.Values.GetSourceInfo(Name) ?? _thisElement.Values.GetSourceInfo(string.Empty);
if (propertySourceInfo != null)
return propertySourceInfo.FileName;
return string.Empty;
}
}
public int LineNumber => (_thisElement.Values.GetSourceInfo(Name) ?? _thisElement.Values.GetSourceInfo(string.Empty))?.LineNumber ?? 0;
public Type Type => Prop.Type;
public ConfigurationValidatorBase Validator => Prop.Validator;
public TypeConverter Converter => Prop.Converter;
public string Description => Prop.Description;
internal PropertyInformation(ConfigurationElement thisElement, string propertyName)
{
Name = propertyName;
_thisElement = thisElement;
}
}
}