ElementInformation.IsCollection Property

 

Gets a value indicating whether the associated ConfigurationElement object is a ConfigurationElementCollection collection.

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

public bool IsCollection { get; }

Property Value

Type: System.Boolean

true if the associated ConfigurationElement object is a ConfigurationElementCollection collection; otherwise, false.

The following example shows how to use the IsCollection property.

static public void IsElementCollection()
{

    // Get the current configuration file.
    System.Configuration.Configuration config =
            ConfigurationManager.OpenExeConfiguration(
            ConfigurationUserLevel.None);

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

    // Get the element.
    UrlConfigElement url = section.Simple;

    // Get the collection element.
    UrlsCollection urls = section.Urls;

    bool isCollection =
        url.ElementInformation.IsCollection;
    Console.WriteLine("Url element is a collection? {0}",
        isCollection.ToString());

    isCollection =
       urls.ElementInformation.IsCollection;
    Console.WriteLine("Urls element is a collection? {0}",
        isCollection.ToString());

}

.NET Framework
Available since 2.0
Return to top
Show: