Auf Englisch lesen

Freigeben über


ConfigurationElement.IsReadOnly Methode

Definition

Ruft einen Wert ab, der angibt, ob das ConfigurationElement schreibgeschützt ist.

C#
public virtual bool IsReadOnly ();

Gibt zurück

true, wenn das ConfigurationElement-Objekt schreibgeschützt ist, andernfalls false.

Beispiele

Im folgenden Beispiel wird die Verwendung der IsReadOnly-Methode gezeigt. Es wird in einem benutzerdefinierten Abschnitt verwendet und gibt zurück false.

C#
// Show how to use IsReadOnly.
// It loops to see if the elements are read only. 
static void ReadOnlyElements()
{
    try
    {
        // Get the configuration file.
        System.Configuration.Configuration config =
            ConfigurationManager.OpenExeConfiguration(
            ConfigurationUserLevel.None);

        // Get the MyUrls section.
        UrlsSection myUrlsSection =
            config.GetSection("MyUrls") as UrlsSection;

        UrlsCollection elements = myUrlsSection.Urls;

        IEnumerator elemEnum =
            elements.GetEnumerator();

        int i = 0;
        Console.WriteLine(elements.Count.ToString());

        while (elemEnum.MoveNext())
        {
            Console.WriteLine("The element {0} is read only: {1}",
             elements[i].Name,
             elements[i].IsReadOnly().ToString());
            i += 1;
        }
    }
    catch (ConfigurationErrorsException err)
    {
        Console.WriteLine("[ReadOnlyElements: {0}]",
            err.ToString());
    }
}

Hinweise

Das System definiert Konfigurationselemente, die nicht geändert werden können.

Verwenden Sie die IsReadOnly -Methode, um zu bestimmen, welche Elemente geändert werden können.

Gilt für:

Produkt Versionen
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9