Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Configuration / System / Configuration / ConfigurationValues.cs / 1305376 / ConfigurationValues.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
using System;
using System.Configuration.Internal;
using System.Collections;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Security.Permissions;
using System.Xml;
using System.Globalization;
using System.ComponentModel;
using System.Security;
using System.Text;
namespace System.Configuration {
internal class ConfigurationValues : NameObjectCollectionBase {
private BaseConfigurationRecord _configRecord;
private bool _containsElement;
private bool _containsInvalidValue;
internal ConfigurationValues() : base(StringComparer.Ordinal) {
}
// AssociateContext
//
// Associate a collection of values with a configRecord
//
internal void AssociateContext(BaseConfigurationRecord configRecord) {
_configRecord = configRecord;
// Associate with children
foreach (ConfigurationElement currentElement in ConfigurationElements) {
currentElement.AssociateContext(_configRecord);
}
}
internal bool Contains(string key) {
return (BaseGet(key) != null);
}
internal string GetKey(int index) {
return BaseGetKey(index);
}
/*
internal ConfigurationValue GetConfigValue(int index)
{
return (ConfigurationValue)BaseGet(BaseGetKey(index));
}
*/
internal ConfigurationValue GetConfigValue(string key) {
return (ConfigurationValue)BaseGet(key);
}
internal ConfigurationValue GetConfigValue(int index) {
return (ConfigurationValue)BaseGet(index);
}
internal PropertySourceInfo GetSourceInfo(string key) {
ConfigurationValue configurationValue = GetConfigValue(key);
if (configurationValue != null) {
return configurationValue.SourceInfo;
}
else {
return null;
}
}
internal void ChangeSourceInfo(string key, PropertySourceInfo sourceInfo) {
ConfigurationValue configurationValue = GetConfigValue(key);
if (configurationValue != null) {
configurationValue.SourceInfo = sourceInfo;
}
}
private ConfigurationValue CreateConfigValue(object value, ConfigurationValueFlags valueFlags, PropertySourceInfo sourceInfo) {
if (value != null) {
if (value is ConfigurationElement) {
_containsElement = true;
((ConfigurationElement)value).AssociateContext(_configRecord);
}
else if (value is InvalidPropValue) {
_containsInvalidValue = true;
}
}
ConfigurationValue configValue = new ConfigurationValue(value, valueFlags, sourceInfo);
return configValue;
}
internal void SetValue(string key, object value, ConfigurationValueFlags valueFlags, PropertySourceInfo sourceInfo) {
ConfigurationValue configValue = CreateConfigValue(value, valueFlags, sourceInfo);
BaseSet(key, configValue);
}
#if UNUSED_CODE
private void SetValue(int index, object value, ConfigurationValueFlags valueFlags, PropertySourceInfo sourceInfo) {
ConfigurationValue configValue = CreateConfigValue(value, valueFlags, sourceInfo);
BaseSet(index, configValue);
}
#endif
internal object this[string key] {
get {
ConfigurationValue configValue = GetConfigValue(key);
if (configValue != null) {
return configValue.Value;
}
else {
return null;
}
}
set {
SetValue(key, value, ConfigurationValueFlags.Modified, null);
}
}
internal object this[int index] {
get {
ConfigurationValue configValue = GetConfigValue(index);
if (configValue != null) {
return configValue.Value;
}
else {
return null;
}
}
#if UNUSED_CODE
set {
SetValue(index, value, ConfigurationValueFlags.Modified, null);
}
#endif
}
internal void Clear() {
BaseClear();
}
internal object SyncRoot { get { return this; } }
internal ConfigurationValueFlags RetrieveFlags(string key) {
ConfigurationValue configurationValue = (ConfigurationValue)BaseGet(key);
if (configurationValue != null) {
return configurationValue.ValueFlags;
}
else {
return ConfigurationValueFlags.Default;
}
}
internal bool IsModified(string key) {
ConfigurationValue configurationValue = (ConfigurationValue)BaseGet(key);
if (configurationValue != null) {
return ((configurationValue.ValueFlags & ConfigurationValueFlags.Modified) != 0);
}
else {
return false;
}
}
internal bool IsInherited(string key) {
ConfigurationValue configurationValue = (ConfigurationValue)BaseGet(key);
if (configurationValue != null) {
return ((configurationValue.ValueFlags & ConfigurationValueFlags.Inherited) != 0);
}
else {
return false;
}
}
internal IEnumerable ConfigurationElements {
get {
if (_containsElement) {
return new ConfigurationElementsCollection(this);
}
else {
return EmptyCollectionInstance;
}
}
}
internal IEnumerable InvalidValues {
get {
if (_containsInvalidValue) {
return new InvalidValuesCollection(this);
}
else {
return EmptyCollectionInstance;
}
}
}
static IEnumerable s_emptyCollection;
static IEnumerable EmptyCollectionInstance {
get {
if (s_emptyCollection == null) {
s_emptyCollection = new EmptyCollection();
}
return s_emptyCollection;
}
}
private class EmptyCollection : IEnumerable {
IEnumerator _emptyEnumerator;
private class EmptyCollectionEnumerator : IEnumerator {
bool IEnumerator.MoveNext() {
return false;
}
Object IEnumerator.Current {
get {
return null;
}
}
void IEnumerator.Reset() {
}
}
internal EmptyCollection() {
_emptyEnumerator = new EmptyCollectionEnumerator();
}
IEnumerator IEnumerable.GetEnumerator() {
return _emptyEnumerator;
}
}
private class ConfigurationElementsCollection : IEnumerable {
ConfigurationValues _values;
internal ConfigurationElementsCollection(ConfigurationValues values) {
_values = values;
}
IEnumerator IEnumerable.GetEnumerator() {
if (_values._containsElement) {
for (int index = 0; index < _values.Count; index++) {
object value = _values[index];
if (value is ConfigurationElement) {
yield return value;
}
}
}
}
}
private class InvalidValuesCollection : IEnumerable {
ConfigurationValues _values;
internal InvalidValuesCollection(ConfigurationValues values) {
_values = values;
}
IEnumerator IEnumerable.GetEnumerator() {
if (_values._containsInvalidValue) {
for (int index = 0; index < _values.Count; index++) {
object value = _values[index];
if (value is InvalidPropValue) {
yield return value;
}
}
}
}
}
/*
internal bool IsLocked(string key)
{
ConfigurationValue configurationValue = (ConfigurationValue)BaseGet(key);
if (configurationValue != null)
return ((configurationValue.ValueFlags & ConfigurationValueFlags.Locked) != 0);
else
return false;
}
internal bool IsReadOnly(string key)
{
ConfigurationValue configurationValue = (ConfigurationValue)BaseGet(key);
if (configurationValue != null)
return ((configurationValue.ValueFlags & ConfigurationValueFlags.ReadOnly) != 0);
else
return false;
}
*/
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
using System;
using System.Configuration.Internal;
using System.Collections;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Security.Permissions;
using System.Xml;
using System.Globalization;
using System.ComponentModel;
using System.Security;
using System.Text;
namespace System.Configuration {
internal class ConfigurationValues : NameObjectCollectionBase {
private BaseConfigurationRecord _configRecord;
private bool _containsElement;
private bool _containsInvalidValue;
internal ConfigurationValues() : base(StringComparer.Ordinal) {
}
// AssociateContext
//
// Associate a collection of values with a configRecord
//
internal void AssociateContext(BaseConfigurationRecord configRecord) {
_configRecord = configRecord;
// Associate with children
foreach (ConfigurationElement currentElement in ConfigurationElements) {
currentElement.AssociateContext(_configRecord);
}
}
internal bool Contains(string key) {
return (BaseGet(key) != null);
}
internal string GetKey(int index) {
return BaseGetKey(index);
}
/*
internal ConfigurationValue GetConfigValue(int index)
{
return (ConfigurationValue)BaseGet(BaseGetKey(index));
}
*/
internal ConfigurationValue GetConfigValue(string key) {
return (ConfigurationValue)BaseGet(key);
}
internal ConfigurationValue GetConfigValue(int index) {
return (ConfigurationValue)BaseGet(index);
}
internal PropertySourceInfo GetSourceInfo(string key) {
ConfigurationValue configurationValue = GetConfigValue(key);
if (configurationValue != null) {
return configurationValue.SourceInfo;
}
else {
return null;
}
}
internal void ChangeSourceInfo(string key, PropertySourceInfo sourceInfo) {
ConfigurationValue configurationValue = GetConfigValue(key);
if (configurationValue != null) {
configurationValue.SourceInfo = sourceInfo;
}
}
private ConfigurationValue CreateConfigValue(object value, ConfigurationValueFlags valueFlags, PropertySourceInfo sourceInfo) {
if (value != null) {
if (value is ConfigurationElement) {
_containsElement = true;
((ConfigurationElement)value).AssociateContext(_configRecord);
}
else if (value is InvalidPropValue) {
_containsInvalidValue = true;
}
}
ConfigurationValue configValue = new ConfigurationValue(value, valueFlags, sourceInfo);
return configValue;
}
internal void SetValue(string key, object value, ConfigurationValueFlags valueFlags, PropertySourceInfo sourceInfo) {
ConfigurationValue configValue = CreateConfigValue(value, valueFlags, sourceInfo);
BaseSet(key, configValue);
}
#if UNUSED_CODE
private void SetValue(int index, object value, ConfigurationValueFlags valueFlags, PropertySourceInfo sourceInfo) {
ConfigurationValue configValue = CreateConfigValue(value, valueFlags, sourceInfo);
BaseSet(index, configValue);
}
#endif
internal object this[string key] {
get {
ConfigurationValue configValue = GetConfigValue(key);
if (configValue != null) {
return configValue.Value;
}
else {
return null;
}
}
set {
SetValue(key, value, ConfigurationValueFlags.Modified, null);
}
}
internal object this[int index] {
get {
ConfigurationValue configValue = GetConfigValue(index);
if (configValue != null) {
return configValue.Value;
}
else {
return null;
}
}
#if UNUSED_CODE
set {
SetValue(index, value, ConfigurationValueFlags.Modified, null);
}
#endif
}
internal void Clear() {
BaseClear();
}
internal object SyncRoot { get { return this; } }
internal ConfigurationValueFlags RetrieveFlags(string key) {
ConfigurationValue configurationValue = (ConfigurationValue)BaseGet(key);
if (configurationValue != null) {
return configurationValue.ValueFlags;
}
else {
return ConfigurationValueFlags.Default;
}
}
internal bool IsModified(string key) {
ConfigurationValue configurationValue = (ConfigurationValue)BaseGet(key);
if (configurationValue != null) {
return ((configurationValue.ValueFlags & ConfigurationValueFlags.Modified) != 0);
}
else {
return false;
}
}
internal bool IsInherited(string key) {
ConfigurationValue configurationValue = (ConfigurationValue)BaseGet(key);
if (configurationValue != null) {
return ((configurationValue.ValueFlags & ConfigurationValueFlags.Inherited) != 0);
}
else {
return false;
}
}
internal IEnumerable ConfigurationElements {
get {
if (_containsElement) {
return new ConfigurationElementsCollection(this);
}
else {
return EmptyCollectionInstance;
}
}
}
internal IEnumerable InvalidValues {
get {
if (_containsInvalidValue) {
return new InvalidValuesCollection(this);
}
else {
return EmptyCollectionInstance;
}
}
}
static IEnumerable s_emptyCollection;
static IEnumerable EmptyCollectionInstance {
get {
if (s_emptyCollection == null) {
s_emptyCollection = new EmptyCollection();
}
return s_emptyCollection;
}
}
private class EmptyCollection : IEnumerable {
IEnumerator _emptyEnumerator;
private class EmptyCollectionEnumerator : IEnumerator {
bool IEnumerator.MoveNext() {
return false;
}
Object IEnumerator.Current {
get {
return null;
}
}
void IEnumerator.Reset() {
}
}
internal EmptyCollection() {
_emptyEnumerator = new EmptyCollectionEnumerator();
}
IEnumerator IEnumerable.GetEnumerator() {
return _emptyEnumerator;
}
}
private class ConfigurationElementsCollection : IEnumerable {
ConfigurationValues _values;
internal ConfigurationElementsCollection(ConfigurationValues values) {
_values = values;
}
IEnumerator IEnumerable.GetEnumerator() {
if (_values._containsElement) {
for (int index = 0; index < _values.Count; index++) {
object value = _values[index];
if (value is ConfigurationElement) {
yield return value;
}
}
}
}
}
private class InvalidValuesCollection : IEnumerable {
ConfigurationValues _values;
internal InvalidValuesCollection(ConfigurationValues values) {
_values = values;
}
IEnumerator IEnumerable.GetEnumerator() {
if (_values._containsInvalidValue) {
for (int index = 0; index < _values.Count; index++) {
object value = _values[index];
if (value is InvalidPropValue) {
yield return value;
}
}
}
}
}
/*
internal bool IsLocked(string key)
{
ConfigurationValue configurationValue = (ConfigurationValue)BaseGet(key);
if (configurationValue != null)
return ((configurationValue.ValueFlags & ConfigurationValueFlags.Locked) != 0);
else
return false;
}
internal bool IsReadOnly(string key)
{
ConfigurationValue configurationValue = (ConfigurationValue)BaseGet(key);
if (configurationValue != null)
return ((configurationValue.ValueFlags & ConfigurationValueFlags.ReadOnly) != 0);
else
return false;
}
*/
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- CodeMethodReturnStatement.cs
- BitVector32.cs
- HttpFileCollectionBase.cs
- AccessControlList.cs
- ScriptResourceInfo.cs
- KeyProperty.cs
- ActivityExecutor.cs
- Rfc4050KeyFormatter.cs
- MDIControlStrip.cs
- LinqDataSourceValidationException.cs
- SymLanguageType.cs
- COAUTHIDENTITY.cs
- ActiveXSite.cs
- CodeDelegateInvokeExpression.cs
- EndpointAddressProcessor.cs
- CrossContextChannel.cs
- Int32CAMarshaler.cs
- MiniAssembly.cs
- XmlSchemaRedefine.cs
- CreateRefExpr.cs
- ComponentRenameEvent.cs
- RsaSecurityToken.cs
- MenuCommand.cs
- BitmapEffectState.cs
- TextProviderWrapper.cs
- ScriptResourceInfo.cs
- PermissionSetEnumerator.cs
- Blend.cs
- HttpListenerResponse.cs
- hebrewshape.cs
- TransformerTypeCollection.cs
- ErrorEventArgs.cs
- ImageCodecInfoPrivate.cs
- Attribute.cs
- Simplifier.cs
- SqlDataSourceConfigureSelectPanel.cs
- DataGridViewAddColumnDialog.cs
- XmlSchemaAppInfo.cs
- ModelPropertyDescriptor.cs
- SubqueryRules.cs
- ResXResourceWriter.cs
- NameValueConfigurationElement.cs
- MenuItemStyleCollection.cs
- XamlToRtfParser.cs
- AbsoluteQuery.cs
- FragmentQueryKB.cs
- Int16Storage.cs
- TimeEnumHelper.cs
- ProfileService.cs
- EmbeddedMailObject.cs
- DefaultPrintController.cs
- GlobalizationSection.cs
- OutputScopeManager.cs
- OleDbError.cs
- PropertyGridEditorPart.cs
- PipelineDeploymentState.cs
- HtmlControl.cs
- PathHelper.cs
- UnsafeNativeMethods.cs
- FormatException.cs
- DefaultAsyncDataDispatcher.cs
- SqlConnectionPoolGroupProviderInfo.cs
- InvalidateEvent.cs
- CodeExpressionCollection.cs
- PeerTransportListenAddressConverter.cs
- ControlUtil.cs
- COM2FontConverter.cs
- VariableQuery.cs
- PreparingEnlistment.cs
- XmlDownloadManager.cs
- ListViewItem.cs
- OdbcTransaction.cs
- WsatConfiguration.cs
- SecurityTokenSpecification.cs
- ProfileEventArgs.cs
- Version.cs
- UIAgentMonitor.cs
- SerializationObjectManager.cs
- ResolvedKeyFrameEntry.cs
- ToolstripProfessionalRenderer.cs
- PeerEndPoint.cs
- ZipIOZip64EndOfCentralDirectoryLocatorBlock.cs
- BoundPropertyEntry.cs
- Keywords.cs
- IntegerValidator.cs
- CacheDict.cs
- Compilation.cs
- DocumentOrderQuery.cs
- JulianCalendar.cs
- GradientPanel.cs
- GridErrorDlg.cs
- SaveFileDialog.cs
- PersonalizationStateInfo.cs
- KeyPullup.cs
- ChangeProcessor.cs
- ZipPackagePart.cs
- QilLiteral.cs
- _IPv4Address.cs
- Crc32Helper.cs
- DataDocumentXPathNavigator.cs