Configuration Element Collection Section

Posted by Matt on Stack Overflow See other posts from Stack Overflow or by Matt
Published on 2010-08-24T15:18:44Z Indexed on 2011/02/19 7:25 UTC
Read the original article Hit count: 244

Filed under:
|
|

I would like to set up a custom app configuration element collection section like this

<logSectionGroup>
    <logSection name="Testttt">
        <properties name ="Pride">
           <pathName="TestingLog.txt"/>
           <deleteRetention="100"/>
           <deleteZeroRetention="5"/>
           <wildcard="*.txt"/>
        </properties>
        <properties name ="Adhoc">
           <pathName="blah.txt"/>
           <deleteRetention="70"/>
           <deleteZeroRetention="3"/>
           <wildcard="*.*"/>
        </properties>
    </logSection>
</logSectionGroup>

Is this possible? Properties would be the configuration element, and log section would be the configuration element collection. The problem is, I've only seen where you can have multiple instances of a single element instead of multiple elements.

<Section name="Section1">     
    <Section name="Section1">
        <SubSection name="SubSection1">
            <Item name="Item1" />
            <Item name="Item2" />
        </SubSection>
        <SubSection name="SubSection2">
            <Item name="Item1" />
            <Item name="Item2" />
        </SubSection>
</Section>

When you use GetElementKey() you have it return element "name" in the above example but how would you return 4 different elements like "pathName" "deleteRetention" etc.

Here is my Definition for PropElement

Public Class PropElement
Inherits ConfigurationElement

<ConfigurationProperty("pathName", IsRequired:=True)> _
Public Property PathName() As String
    Get
        Return CStr(Me("pathName"))
    End Get
    Set(ByVal value As String)
        Me("pathName") = value
    End Set
End Property

<ConfigurationProperty("deleteRetention", DefaultValue:="0", IsRequired:=False)> _
Public Property DeleteRetention() As Integer
    Get
        Return CStr(Me("deleteRetention"))
    End Get
    Set(ByVal value As Integer)
        Me("deleteRetention") = value
    End Set
End Property
<ConfigurationProperty("deleteZeroRetention", DefaultValue:="0", IsRequired:=False)> _
Public Property DeleteZeroRetention() As Integer
    Get
        Return CStr(Me("deleteZeroRetention"))
    End Get
    Set(ByVal value As Integer)
        Me("deleteZeroRetention") = value
    End Set
End Property
<ConfigurationProperty("wildcard", DefaultValue:="*.*", IsRequired:=False)> _
Public Property Wildcard() As String
    Get
        Return CStr(Me("wildcard"))
    End Get
    Set(ByVal value As String)
        Me("wildcard") = value
    End Set
End Property

End Class

© Stack Overflow or respective owner

Related posts about .NET

Related posts about vb.net