ApacheMimeTypesToDotNet.Program.WriteDictionaryToCsharpMimeTypesClass C# (CSharp) Method

WriteDictionaryToCsharpMimeTypesClass() private static method

private static WriteDictionaryToCsharpMimeTypesClass ( string>.Dictionary dictionary ) : void
dictionary string>.Dictionary
return void
        private static void WriteDictionaryToCsharpMimeTypesClass(Dictionary<string, string> dictionary)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("using System;");
            sb.AppendLine("using System.Collections.Generic;");
            sb.AppendLine();
            sb.AppendFormat("namespace {0}", NameSpace).AppendLine();
            sb.AppendLine("{");
            sb.Append(Indent(1))
                .AppendFormat("class {0}", ClassName)
                .AppendLine();
            sb.Append(Indent(1))
                .AppendLine("{");
            sb.Append(Indent(2))
                .AppendFormat("public static Dictionary<string, string> {0} = new Dictionary<string, string>", DictionaryName)
                .AppendLine();
            sb.Append(Indent(2))
                .AppendLine("{");
            foreach (string extension in dictionary.Keys.OrderBy(k => k))
            {
                sb.Append(Indent(3))
                    .AppendFormat("{{ \"{0}\", \"{1}\" }},", extension, dictionary[extension])
                    .AppendLine();
            }
            sb.Append(Indent(2))
                .AppendLine("};");
            sb.Append(Indent(1))
                .AppendLine("}");
            sb.AppendLine("}");

            using (TextWriter writer = File.CreateText(FileName))
            {
                writer.Write(sb.ToString());
            }
        }