ElementInformation
Contains meta-information about an individual element within the configuration. This class cannot be inherited.
using System.Collections;
namespace System.Configuration
{
public sealed class ElementInformation
{
private readonly ConfigurationElement _thisElement;
private ConfigurationException[] _errors;
private PropertyInformationCollection _internalProperties;
public PropertyInformationCollection Properties => _internalProperties ?? (_internalProperties = new PropertyInformationCollection(_thisElement));
public bool IsPresent => _thisElement.ElementPresent;
public bool IsLocked {
get {
if ((_thisElement.ItemLocked & ConfigurationValueFlags.Locked) != 0)
return (_thisElement.ItemLocked & ConfigurationValueFlags.Inherited) != ConfigurationValueFlags.Default;
return false;
}
}
public bool IsCollection {
get {
ConfigurationElementCollection configurationElementCollection = _thisElement as ConfigurationElementCollection;
if (configurationElementCollection == null && _thisElement.Properties.DefaultCollectionProperty != null)
configurationElementCollection = (_thisElement[_thisElement.Properties.DefaultCollectionProperty] as ConfigurationElementCollection);
return configurationElementCollection != null;
}
}
public string Source => _thisElement.Values.GetSourceInfo(_thisElement.ElementTagName)?.FileName;
public int LineNumber => _thisElement.Values.GetSourceInfo(_thisElement.ElementTagName)?.LineNumber ?? 0;
public Type Type => _thisElement.GetType();
public ConfigurationValidatorBase Validator => _thisElement.ElementProperty.Validator;
public ICollection Errors => _errors ?? (_errors = GetReadOnlyErrorsList());
internal ElementInformation(ConfigurationElement thisElement)
{
_thisElement = thisElement;
}
internal PropertySourceInfo PropertyInfoInternal()
{
return _thisElement.PropertyInfoInternal(_thisElement.ElementTagName);
}
internal void ChangeSourceAndLineNumber(PropertySourceInfo sourceInformation)
{
_thisElement.Values.ChangeSourceInfo(_thisElement.ElementTagName, sourceInformation);
}
private ConfigurationException[] GetReadOnlyErrorsList()
{
ArrayList errorsList = _thisElement.GetErrorsList();
int count = errorsList.Count;
ConfigurationException[] array = new ConfigurationException[errorsList.Count];
if (count != 0)
errorsList.CopyTo(array, 0);
return array;
}
}
}