Sources/Domenici.Utilities.Configuration/Configuration/StrongTyper.cs
/// <summary>
/// Generate a C# class that stong-types the settings.
/// </summary>
/// <returns></returns>
Generate a C# class that stong-types the settings.
Generate a C# class that stong - types the settings .
private string CreateOutput()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(Tabs(0) + "//------------------------------------------------------------------------------\r\n");
            sb.Append(Tabs(0) + "// <auto-generated>\r\n");
            sb.Append(Tabs(0) + "// This code was automatically generated by the Domenici.Utilities.Configuration tool.\r\n");
            sb.Append(Tabs(0) + "//\r\n");
            sb.Append(Tabs(0) + "// Changes to this file may cause incorrect behavior and will be lost if\r\n");
            sb.Append(Tabs(0) + "// the code is regenerated.\r\n");
            sb.Append(Tabs(0) + "// </auto-generated>\r\n");
            sb.Append(Tabs(0) + "//------------------------------------------------------------------------------\r\n");
            sb.Append(Tabs(0) + "\r\n");
            sb.Append(Tabs(0) + "namespace Domenici.Utilities.Configuration\r\n");
            sb.Append(Tabs(0) + "{\r\n");
            sb.Append(Tabs(1) + string.Format("public static class {0}\r\n", FormatName(this.libraryName + "Settings")));
            sb.Append(Tabs(1) + "{\r\n");
            foreach (SettingProperties setting in this.settingsList)
            {
                if (0 <= setting.Key.IndexOf(SettingsManager.SectionSeparator))
                {
                    string[] sections = setting.Key.Split(new string[] { SettingsManager.SectionSeparator }, StringSplitOptions.RemoveEmptyEntries);
                    for (int i = 0; i < sections.Length; i++)
                    {
                        if (i < sections.Length - 1)
                        {
                            sb.Append(Tabs((i + 2)) + string.Format("public static partial class {0}\r\n", FormatName(sections[i])));
                            sb.Append(Tabs((i + 2)) + "{\r\n");
                        }
                    }
                    sb.Append(Tabs(sections.Length + 1) + string.Format("public static {0} {1} ", string.IsNullOrEmpty(setting.Type) ? "string" : setting.Type, FormatName(sections[sections.Length - 1])));
                    sb.Append("{ get { ");
                    sb.Append(string.Format("return ({0})SettingsManager.GetValue(\"{1}\", typeof({0})); ", setting.Type, setting.Key));
                    sb.Append("} }\r\n");
                    for (int i = sections.Length; i >= 0; i--)
                    {
                        if (i < sections.Length - 1)
                        {
                            sb.Append(Tabs(i + 2) + "}\r\n");
                        }
                    }
                }
                else
                {
                    sb.Append(Tabs(2) + string.Format("public static {0} {1} ", string.IsNullOrEmpty(setting.Type) ? "string" : setting.Type, FormatName(setting.Key)));
                    sb.Append("{ get { ");
                    sb.Append(string.Format("return ({0})SettingsManager.GetValue(\"{1}\", typeof({0}));", setting.Type, setting.Key));
                    sb.Append("} }\r\n");
                }
            }
            sb.Append(Tabs(1) + "}\r\n");
            sb.Append(Tabs(0) + "}\r\n");
            return sb.ToString();
        }
private string CreateOutput ( ) { StringBuilder sb = new StringBuilder ( ) ; sb . Append ( Tabs ( 0 ) + " \r \n " ) ; sb . Append ( Tabs ( 0 ) + " \r \n " ) ; sb . Append ( Tabs ( 0 ) + " \r \n " ) ; sb . Append ( Tabs ( 0 ) + " \r \n " ) ; sb . Append ( Tabs ( 0 ) + " \r \n " ) ; sb . Append ( Tabs ( 0 ) + " \r \n " ) ; sb . Append ( Tabs ( 0 ) + " \r \n " ) ; sb . Append ( Tabs ( 0 ) + " \r \n " ) ; sb . Append ( Tabs ( 0 ) + " \r \n " ) ; sb . Append ( Tabs ( 0 ) + " \r \n " ) ; sb . Append ( Tabs ( 0 ) + " \r \n " ) ; sb . Append ( Tabs ( 1 ) + string . Format ( " \r \n " , FormatName ( this . libraryName + " " ) ) ) ; sb . Append ( Tabs ( 1 ) + " \r \n " ) ; foreach ( SettingProperties setting in this . settingsList ) { if ( 0 <= setting . Key . IndexOf ( SettingsManager . SectionSeparator ) ) { string [ ] sections = setting . Key . Split ( new string [ ] { SettingsManager . SectionSeparator } , StringSplitOptions . RemoveEmptyEntries ) ; for ( int i = 0 ; i < sections . Length ; i ++ ) { if ( i < sections . Length - 1 ) { sb . Append ( Tabs ( ( i + 2 ) ) + string . Format ( " \r \n " , FormatName ( sections [ i ] ) ) ) ; sb . Append ( Tabs ( ( i + 2 ) ) + " \r \n " ) ; } } sb . Append ( Tabs ( sections . Length + 1 ) + string . Format ( " " , string . IsNullOrEmpty ( setting . Type ) ? " " : setting . Type , FormatName ( sections [ sections . Length - 1 ] ) ) ) ; sb . Append ( " " ) ; sb . Append ( string . Format ( " \" \" " , setting . Type , setting . Key ) ) ; sb . Append ( " \r \n " ) ; for ( int i = sections . Length ; i >= 0 ; i -- ) { if ( i < sections . Length - 1 ) { sb . Append ( Tabs ( i + 2 ) + " \r \n " ) ; } } } else { sb . Append ( Tabs ( 2 ) + string . Format ( " " , string . IsNullOrEmpty ( setting . Type ) ? " " : setting . Type , FormatName ( setting . Key ) ) ) ; sb . Append ( " " ) ; sb . Append ( string . Format ( " \" \" " , setting . Type , setting . Key ) ) ; sb . Append ( " \r \n " ) ; } } sb . Append ( Tabs ( 1 ) + " \r \n " ) ; sb . Append ( Tabs ( 0 ) + " \r \n " ) ; return sb . ToString ( ) ; }
Generate a C# class that stong-types the settings.
Generate a C# class that stong - types the settings .
None