System.Configuration.SettingsProviderCollection.Add C# (CSharp) Метод

Add() публичный Метод

public Add ( ProviderBase provider ) : void
provider ProviderBase
Результат void
       public override void Add(ProviderBase provider) {
           if( provider == null )
           {
               throw new ArgumentNullException( "provider" );
           }

           if( !( provider is SettingsProvider ) )
           {
                throw new ArgumentException(SR.GetString(SR.Config_provider_must_implement_type, typeof(SettingsProvider).ToString()), "provider");
           }
 
           base.Add( provider );
       }

Usage Example

Пример #1
0
        /// <summary>
        /// Ensures this class is initialized. Initialization involves reflecting over properties and building
        /// a list of SettingsProperty's.
        /// </summary>
        private void EnsureInitialized()
        {
            // Initialization method -
            // be careful not to access properties here to prevent stack overflow.

            if (!_initialized)
            {
                _initialized = true;

                Type type = GetType();

                if (_context == null)
                {
                    _context = new SettingsContext();
                }
                _context["GroupName"]         = type.FullName;
                _context["SettingsKey"]       = SettingsKey;
                _context["SettingsClassType"] = type;

                PropertyInfo[] properties = SettingsFilter(type.GetProperties(BindingFlags.Instance | BindingFlags.Public));
                _classAttributes = type.GetCustomAttributes(false);

                if (_settings == null)
                {
                    _settings = new SettingsPropertyCollection();
                }

                if (_providers == null)
                {
                    _providers = new SettingsProviderCollection();
                }

                for (int i = 0; i < properties.Length; i++)
                {
                    SettingsProperty sp = CreateSetting(properties[i]);
                    if (sp != null)
                    {
                        _settings.Add(sp);

                        if (sp.Provider != null && _providers[sp.Provider.Name] == null)
                        {
                            _providers.Add(sp.Provider);
                        }
                    }
                }
            }
        }
All Usage Examples Of System.Configuration.SettingsProviderCollection::Add
SettingsProviderCollection