Simple XML, no collections

For this configuration XML:
<code-gen>
    <language name="c#" version="4.0"/>
    <options generate-regions="[true]" partial-class="[true]" indentation="4"/>
</code-gen>
.NET Configuration Code Generator generates the following C# code:
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.235
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------



public sealed class CodeGen {
    
    private static CodeGenSection _config;
    
    static CodeGen() {
        _config = ((CodeGenSection)(global::System.Configuration.ConfigurationManager.GetSection("code-gen")));
    }
    
    private CodeGen() {
    }
    
    public static CodeGenSection Config {
        get {
            return _config;
        }
    }
}

public sealed class CodeGenSection : System.Configuration.ConfigurationSection {
    
    [System.Configuration.ConfigurationPropertyAttribute("language")]
    public LanguageElement Language {
        get {
            return ((LanguageElement)(this["language"]));
        }
    }
    
    [System.Configuration.ConfigurationPropertyAttribute("options")]
    public OptionsElement Options {
        get {
            return ((OptionsElement)(this["options"]));
        }
    }
    
    public sealed class LanguageElement : System.Configuration.ConfigurationElement {
        
        [System.Configuration.ConfigurationPropertyAttribute("name", IsRequired=true)]
        public string Name {
            get {
                return ((string)(this["name"]));
            }
            set {
                this["name"] = value;
            }
        }
        
        [System.Configuration.ConfigurationPropertyAttribute("version", IsRequired=true)]
        public double Version {
            get {
                return ((double)(this["version"]));
            }
            set {
                this["version"] = value;
            }
        }
    }
    
    public sealed class OptionsElement : System.Configuration.ConfigurationElement {
        
        [System.Configuration.ConfigurationPropertyAttribute("generate-regions", IsRequired=false)]
        public bool GenerateRegions {
            get {
                return ((bool)(this["generate-regions"]));
            }
            set {
                this["generate-regions"] = value;
            }
        }
        
        [System.Configuration.ConfigurationPropertyAttribute("partial-class", IsRequired=false)]
        public bool PartialClass {
            get {
                return ((bool)(this["partial-class"]));
            }
            set {
                this["partial-class"] = value;
            }
        }
        
        [System.Configuration.ConfigurationPropertyAttribute("indentation", IsRequired=true)]
        public long Indentation {
            get {
                return ((long)(this["indentation"]));
            }
            set {
                this["indentation"] = value;
            }
        }
    }
}
and the following Visual BASIC code:
'------------------------------------------------------------------------------
' <auto-generated>
'     This code was generated by a tool.
'     Runtime Version:4.0.30319.235
'
'     Changes to this file may cause incorrect behavior and will be lost if
'     the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------

Option Strict Off
Option Explicit On



Public NotInheritable Class CodeGen
    
    Private Shared _config As CodeGenSection
    
    Shared Sub New()
        _config = CType(Global.System.Configuration.ConfigurationManager.GetSection("code-gen"),CodeGenSection)
    End Sub
    
    Private Sub New()
        MyBase.New
    End Sub
    
    Public Shared ReadOnly Property Config() As CodeGenSection
        Get
            Return _config
        End Get
    End Property
End Class

Public NotInheritable Class CodeGenSection
    Inherits System.Configuration.ConfigurationSection
    
    <System.Configuration.ConfigurationPropertyAttribute("language")>  _
    Public ReadOnly Property Language() As LanguageElement
        Get
            Return CType(Me("language"),LanguageElement)
        End Get
    End Property
    
    <System.Configuration.ConfigurationPropertyAttribute("options")>  _
    Public ReadOnly Property Options() As OptionsElement
        Get
            Return CType(Me("options"),OptionsElement)
        End Get
    End Property
    
    Public NotInheritable Class LanguageElement
        Inherits System.Configuration.ConfigurationElement
        
        <System.Configuration.ConfigurationPropertyAttribute("name", IsRequired:=true)>  _
        Public Property Name() As String
            Get
                Return CType(Me("name"),String)
            End Get
            Set
                Me("name") = value
            End Set
        End Property
        
        <System.Configuration.ConfigurationPropertyAttribute("version", IsRequired:=true)>  _
        Public Property Version() As Double
            Get
                Return CType(Me("version"),Double)
            End Get
            Set
                Me("version") = value
            End Set
        End Property
    End Class
    
    Public NotInheritable Class OptionsElement
        Inherits System.Configuration.ConfigurationElement
        
        <System.Configuration.ConfigurationPropertyAttribute("generate-regions", IsRequired:=false)>  _
        Public Property GenerateRegions() As Boolean
            Get
                Return CType(Me("generate-regions"),Boolean)
            End Get
            Set
                Me("generate-regions") = value
            End Set
        End Property
        
        <System.Configuration.ConfigurationPropertyAttribute("partial-class", IsRequired:=false)>  _
        Public Property PartialClass() As Boolean
            Get
                Return CType(Me("partial-class"),Boolean)
            End Get
            Set
                Me("partial-class") = value
            End Set
        End Property
        
        <System.Configuration.ConfigurationPropertyAttribute("indentation", IsRequired:=true)>  _
        Public Property Indentation() As Long
            Get
                Return CType(Me("indentation"),Long)
            End Get
            Set
                Me("indentation") = value
            End Set
        End Property
    End Class
End Class

Last edited Jul 11, 2011 at 7:44 AM by jeevanjj, version 3

Comments

No comments yet.