Exportar (0) Imprimir
Expandir Tudo
Este artigo foi traduzido por máquina. Coloque o ponteiro do mouse sobre as frases do artigo para ver o texto original. Mais informações.
Tradução
Original

ConfigurationElementCollection Classe

Representa um elemento de configuração que contém uma coleção de elementos filho.

Namespace:  System.Configuration
Assembly:  System.Configuration (em System.Configuration. dll)

public abstract class ConfigurationElementCollection : ConfigurationElement, 
	ICollection, IEnumerable

The ConfigurationElementCollection represents a collection of elements within a configuration file.

ObservaçãoObservação:

An elemento within a arquivo de configuração refers to a Basic XML element or a seção.Um elemento simples é uma marca XML com atributos relacionados, se houver algum.Um elemento simples constitui uma seção.COMPLEX Seções can contain one or more elements Simple, a of elements, and other Seções.

You use the ConfigurationElementCollection to work with a collection of ConfigurationElement objects.Implement this class to add collections of custom ConfigurationElement elements to a ConfigurationSection.

OBSERVAÇÕES PARA Implementers:

You can use a or a () Coding to Criar a .

The programmatic model requires that for each element attribute you create a property to get and set its value, and that you add it to the internal property bag of the underlying ConfigurationElement base class.

O modelo declarativo, também conhecido como o modelo atributo, permite que você para definir um atributo de elemento usando uma propriedade e configurá-lo com atributos.Esses atributos instruem o sistema de configuração ASP.NET sobre os tipos de propriedades e seus valores padrão.O ASP.NET pode usar reflexo para obter essas informações e, em seguida, criar o elemento Propriedade objetos e executar a inicialização necessária.

The following code example shows how to implement a custom ConfigurationElementCollection.For examples of related custom types, see ConfigurationSection and ConfigurationElement.


using System;
using System.Configuration;
using System.Collections;


namespace Samples.AspNet
{
    // Define the UrlsCollection that contains 
    // UrlsConfigElement elements.
    public class UrlsCollection :
        ConfigurationElementCollection
    {
        public UrlsCollection()
        {
            UrlConfigElement url =
                (UrlConfigElement)CreateNewElement();
            // Add the element to the collection.
            Add(url);
        }

        public override 
            ConfigurationElementCollectionType CollectionType
        {
            get
            {
                return 
                    ConfigurationElementCollectionType.AddRemoveClearMap;
            }
        }

        protected override 
            ConfigurationElement CreateNewElement()
        {
            return new UrlConfigElement();
        }


        protected override 
            ConfigurationElement CreateNewElement(
            string elementName)
        {
            return new UrlConfigElement(elementName);
        }


        protected override Object 
            GetElementKey(ConfigurationElement element)
        {
            return ((UrlConfigElement)element).Name;
        }


        public new string AddElementName
        {
            get
            { return base.AddElementName; }

            set
            { base.AddElementName = value; }

        }

        public new string ClearElementName
        {
            get
            { return base.ClearElementName; }

            set
            { base.AddElementName = value; }

        }

        public new string RemoveElementName
        {
            get
            { return base.RemoveElementName; }


        }

        public new int Count
        {

            get { return base.Count; }

        }


        public UrlConfigElement this[int index]
        {
            get
            {
                return (UrlConfigElement)BaseGet(index);
            }
            set
            {
                if (BaseGet(index) != null)
                {
                    BaseRemoveAt(index);
                }
                BaseAdd(index, value);
            }
        }

        new public UrlConfigElement this[string Name]
        {
            get
            {
                return (UrlConfigElement)BaseGet(Name);
            }
        }

        public int IndexOf(UrlConfigElement url)
        {
            return BaseIndexOf(url);
        }

        public void Add(UrlConfigElement url)
        {
            BaseAdd(url);

            // Add custom code here.
        }

        protected override void 
            BaseAdd(ConfigurationElement element)
        {
            BaseAdd(element, false);
            // Add custom code here.
        }

        public void Remove(UrlConfigElement url)
        {
            if (BaseIndexOf(url) >= 0)
                BaseRemove(url.Name);
        }

        public void RemoveAt(int index)
        {
            BaseRemoveAt(index);
        }

        public void Remove(string name)
        {
            BaseRemove(name);
        }

        public void Clear()
        {
            BaseClear();
            // Add custom code here.
        }
    }
}


O seguinte trecho de configuração é usado pelo exemplo anterior.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="MyUrls"
      type="Samples.AspNet.UrlsSection, ConfigurationElement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" 
      allowDefinition="Everywhere" 
      allowExeDefinition="MachineToApplication" 
      restartOnExternalChanges="true" />
  </configSections>
  <MyUrls lockAllElementsExcept="urls">
    <internal 
      name="Microsoft" url="http://www.microsoft.com" port="0" />
      <urls>
        <clear />
        <add 
          name="Microsoft" url="http://www.microsoft.com" port="0"
          lockAllAttributesExcept="port" />
        <add 
          name="Contoso" url="http://www.contoso.com/" port="8080"
          lockAllAttributesExcept="port" lockItem="true" />
      </urls>
  </MyUrls>
</configuration>

System.Object
  System.Configuration.ConfigurationElement
    System.Configuration.ConfigurationElementCollection
      System.Configuration.ConnectionStringSettingsCollection
      System.Configuration.KeyValueConfigurationCollection
      System.Configuration.NameValueConfigurationCollection
      System.Configuration.ProviderSettingsCollection
      System.Configuration.SettingElementCollection
      System.Net.Configuration.AuthenticationModuleElementCollection
      System.Net.Configuration.BypassElementCollection
      System.Net.Configuration.ConnectionManagementElementCollection
      System.Net.Configuration.WebRequestModuleElementCollection
      System.Web.Configuration.AssemblyCollection
      System.Web.Configuration.AuthorizationRuleCollection
      System.Web.Configuration.BufferModesCollection
      System.Web.Configuration.BuildProviderCollection
      System.Web.Configuration.ClientTargetCollection
      System.Web.Configuration.CodeSubDirectoriesCollection
      System.Web.Configuration.CompilerCollection
      System.Web.Configuration.CustomErrorCollection
      System.Web.Configuration.EventMappingSettingsCollection
      System.Web.Configuration.ExpressionBuilderCollection
      System.Web.Configuration.FormsAuthenticationUserCollection
      System.Web.Configuration.HttpHandlerActionCollection
      System.Web.Configuration.HttpModuleActionCollection
      System.Web.Configuration.NamespaceCollection
      System.Web.Configuration.OutputCacheProfileCollection
      System.Web.Configuration.ProfileGroupSettingsCollection
      System.Web.Configuration.ProfilePropertySettingsCollection
      System.Web.Configuration.ProfileSettingsCollection
      System.Web.Configuration.ProtocolCollection
      System.Web.Configuration.RuleSettingsCollection
      System.Web.Configuration.SqlCacheDependencyDatabaseCollection
      System.Web.Configuration.TagMapCollection
      System.Web.Configuration.TagPrefixCollection
      System.Web.Configuration.TransformerInfoCollection
      System.Web.Configuration.TrustLevelCollection
      System.Web.Configuration.UrlMappingCollection
      System.Web.Mobile.DeviceFilterElementCollection
      System.Web.Services.Configuration.ProtocolElementCollection
      System.Web.Services.Configuration.SoapExtensionTypeElementCollection
      System.Web.Services.Configuration.TypeElementCollection
      System.Web.Services.Configuration.WsiProfilesElementCollection
      System.Web.UI.MobileControls.ControlElementCollection
      System.Web.UI.MobileControls.DeviceElementCollection
      System.Xml.Serialization.Configuration.SchemaImporterExtensionElementCollection

Quaisquer membros públicos estático (compartilhados na Visual Basic) desse tipo são Thread seguro. Não há garantia de que qualquer membro de instância seja isento de segmentos.

Contribuições da comunidade

ADICIONAR
Mostrar:
© 2014 Microsoft