Share via


ConfigurationCollectionAttribute(Type) 建構函式

定義

初始化 ConfigurationCollectionAttribute 類別的新執行個體。

public:
 ConfigurationCollectionAttribute(Type ^ itemType);
public ConfigurationCollectionAttribute (Type itemType);
new System.Configuration.ConfigurationCollectionAttribute : Type -> System.Configuration.ConfigurationCollectionAttribute
Public Sub New (itemType As Type)

參數

itemType
Type

要建立的屬性集合型別。

例外狀況

itemTypenull

範例

下列範例示範如何使用 ConfigurationCollectionAttribute

// Declare the Urls collection property using the
// ConfigurationCollectionAttribute.
// This allows to build a nested section that contains
// a collection of elements.
[ConfigurationProperty("urls", IsDefaultCollection = false)]
[ConfigurationCollection(typeof(UrlsCollection),
    AddItemName = "add",
    ClearItemsName = "clear",
    RemoveItemName = "remove")]
public UrlsCollection Urls
{
    get
    {
        UrlsCollection urlsCollection =
            (UrlsCollection)base["urls"];
        return urlsCollection;
    }
}
' Declare the Urls collection property using the
' ConfigurationCollectionAttribute.
' This allows to build a nested section that contains
' a collection of elements.
<ConfigurationProperty("urls", IsDefaultCollection:=False),
    System.Configuration.ConfigurationCollection(GetType(UrlsCollection),
    AddItemName:="add", ClearItemsName:="clear", RemoveItemName:="remove")> _
Public ReadOnly Property Urls() As UrlsCollection
    Get
        Dim urlsCollection As UrlsCollection = CType(MyBase.Item("urls"), UrlsCollection)
        Return urlsCollection
    End Get
End Property

備註

您可以使用這個建構函式來告知 .NET Framework 要建立之屬性集合的自訂類型。

適用於