ConfigurationElement Classe
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Rappresenta un elemento in un file di configurazione.
public ref class ConfigurationElement
public class ConfigurationElement
type ConfigurationElement = class
Public Class ConfigurationElement
- Ereditarietà
-
ConfigurationElement
- Derivato
Esempio
Nell'esempio ConfigurationElement seguente vengono implementati diversi metodi e proprietà della classe. In questo esempio viene ottenuto un ConfigurationSection oggetto per la moduleProvider
sezione e viene ottenuto un ConfigurationElementCollection oggetto da tale sezione. In questo esempio viene eseguita l'iterazione di ogni ConfigurationElement raccolta recuperata.
[ModuleServiceMethod(PassThrough = true)]
public ArrayList GetElementCollection()
{
// Use an ArrayList to transfer objects to the client.
ArrayList arrayOfConfigPropertyBags = new ArrayList();
ServerManager serverManager = new ServerManager();
Configuration administrationConfig = serverManager.GetAdministrationConfiguration();
ConfigurationSection moduleProvidersSection =
administrationConfig.GetSection("moduleProviders");
ConfigurationElementCollection elementCollection =
moduleProvidersSection.GetCollection();
// If there is a configuration element with the name of TestDemo(Modified), delete it.
ConfigurationElement elementtoremove = null;
foreach (ConfigurationElement moduleproviderelement in elementCollection)
{
if(moduleproviderelement.Attributes["name"].Value.ToString() == "TestDemo(Modified)")
{
elementtoremove = moduleproviderelement;
}
}
if (elementtoremove != null)
{
elementCollection.Remove(elementtoremove);
}
foreach (ConfigurationElement moduleproviderelement in elementCollection)
{
PropertyBag elementBag = new PropertyBag();
elementBag[ConfigurationDemoGlobals.SchemaName] =
moduleproviderelement.Schema.Name;
elementBag[ConfigurationDemoGlobals.ElementTagName] =
moduleproviderelement.ElementTagName;
ArrayList attributeArrayList = new ArrayList();
// Loop through all attributes in the element attribute list.
// Get the attribute name and value.
foreach (ConfigurationAttribute attribute in moduleproviderelement.Attributes)
{
PropertyBag attributeBag = new PropertyBag();
attributeBag[ConfigurationDemoGlobals.AttributeName] = attribute.Name;
attributeBag[ConfigurationDemoGlobals.AttributeValue] = attribute.Value;
// Change the value of the provider name "TestDemo" to "TestDemo(Modified)".
if (attribute.Value.ToString() == "TestDemo")
{
// Use any of the following lines to set the attribute value.
// attribute.Value = "TestDemo(Modified)";
moduleproviderelement.SetAttributeValue(
"name", "TestDemo(Modified)");
// moduleproviderelement["name"] = "TestDemo(Modified)";
// Use any of the following lines to retrieve the attribute value.
// attributeBag[ConfigurationDemoGlobals.AttributeName] = "name";
attributeBag[ConfigurationDemoGlobals.AttributeName] =
moduleproviderelement.GetAttributeValue("name");
// attributeBag[ConfigurationDemoGlobals.AttributeName] =
// moduleproviderelement["name"];
// Set the element's lockItem attribute.
moduleproviderelement.SetMetadata("lockItem", true); // persisted in Administration.config
}
attributeArrayList.Add(attributeBag);
}
elementBag[ConfigurationDemoGlobals.AttributeArrayList] = attributeArrayList;
arrayOfConfigPropertyBags.Add(elementBag);
}
// Create a new element. It must have a unique name.
ConfigurationElement newelement;
bool newelementexists = false;
foreach (ConfigurationElement element in elementCollection)
{
if (element.Attributes["name"].Value.ToString() == "TestDemo")
{
newelementexists = true;
}
}
if (!newelementexists)
{
newelement = elementCollection.CreateElement("add");
newelement.Attributes["name"].Value = "TestDemo";
newelement.Attributes["Type"].Value = "TestDemo.TestDemoModuleProvider, TestDemo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=104f78e73dc54601";
elementCollection.Add(newelement);
}
// CommitChanges to persist the changes to Administration.config.
serverManager.CommitChanges();
return arrayOfConfigPropertyBags;
}
Commenti
Si tratta della classe di base per molte entità di configurazione, incluse le sezioni di configurazione, le voci della raccolta e gli elementi annidati in una sezione.
Costruttori
ConfigurationElement() |
Inizializza una nuova istanza della classe ConfigurationElement. |
Proprietà
Attributes |
Ottiene una raccolta di attributi di configurazione contenente l'elenco di attributi per questo elemento. |
ChildElements |
Ottiene tutti gli elementi figlio dell'elemento corrente. |
ElementTagName |
Rappresenta un elemento in un file di configurazione. |
IsLocallyStored |
Ottiene un valore che indica se l'elemento di configurazione viene archiviato in un determinato file di configurazione. |
Item[String] |
Ottiene o imposta un attributo con il nome specificato. |
Methods |
Ottiene una raccolta di metodi per l'elemento di configurazione. |
RawAttributes |
Rappresenta un elemento in un file di configurazione. |
Schema |
Ottiene lo schema per l'elemento corrente. |
Metodi
Delete() |
Rappresenta un elemento in un file di configurazione. |
GetAttribute(String) |
Restituisce un ConfigurationAttribute oggetto che rappresenta l'attributo richiesto. |
GetAttributeValue(String) |
Restituisce il valore dell'attributo specificato. |
GetChildElement(String) |
Restituisce un elemento figlio sotto l'elemento di configurazione corrente e ha il nome specificato. |
GetChildElement(String, Type) |
Restituisce un elemento figlio sotto l'elemento di configurazione corrente e ha il nome e il tipo specificati. |
GetCollection() |
Restituisce la raccolta predefinita per l'elemento di configurazione corrente. |
GetCollection(String) |
Restituisce tutti gli elementi di configurazione che appartengono all'elemento di configurazione corrente. |
GetCollection(String, Type) |
Restituisce l'elemento di configurazione con il nome e il tipo specificati e si trova nell'elemento di configurazione corrente. |
GetCollection(Type) |
Restituisce l'elemento di configurazione con il tipo specificato ed è incluso nell'elemento di configurazione corrente. |
GetMetadata(String) |
Restituisce i valori dei metadati dallo schema degli elementi. |
SetAttributeValue(String, Object) |
Imposta il valore dell'attributo specificato. |
SetMetadata(String, Object) |
Imposta i valori dei metadati dallo schema degli elementi. |