public void WriteDocs(TextWriter writer)
        {
            var indentedWriter = new IndentedTextWriter(writer, " ");
            List<string> names = new List<string>();

            foreach (var code in docs)
            {
                string[] newNames = code.Key.Split('.');
                int same = names.GetEqualsInBeginning(newNames);
                indentedWriter.Indent -= names.Count;
                indentedWriter.Indent += same;
                for (int i = same; i < newNames.Length; i++)
                {
                    indentedWriter.WriteLine(newNames[i]);
                    indentedWriter.Indent++;
                }

                var sortedDocs = new Dictionary<string, List<DocCode>>();
                foreach (var docCode in code.Value)
                {
                    List<DocCode> list = sortedDocs.GetOldOrSetNew(docCode.code.Name);
                    list.Add(docCode);
                }
                foreach (var list in sortedDocs.Values)
                {
                    WriteCode(list, indentedWriter);
                    writer.WriteLine();
                }

                names.Clear();
                names.AddRange(newNames);
            }
        }
        private static void WriteTerminatingStringTemplate(IList<DocCode> list,
            IndentedTextWriter writer, IList<TerminatingStringTemplate> templates)
        {
            //TerminatingStringTemplate.WriteDoc(writer, template);

            var parameterDocs = new Dictionary<string, List<string>>(
                StringComparer.CurrentCultureIgnoreCase);

            var templatesSortedByGame = new Dictionary<string, List<TerminatingStringTemplate>>();

            for (int i = 0; i < templates.Count; i++)
            {
                string key = list[i].languages.ToHumanString();
                List<TerminatingStringTemplate> tempList = templatesSortedByGame.GetOldOrSetNew(key);
                tempList.Add(templates[i]);

                List<string> values = parameterDocs.GetOldOrSetNew(templates[i].Parameter.Name);
                values.AddRange(list[i].parameterDocs[templates[i].Parameter.Name]);
            }

            foreach (var item in templatesSortedByGame)
            {
                writer.WriteLine(item.Key + ":");
                writer.Indent++;
                foreach (var template in item.Value)
                {
                    WriteDoc(writer, template);
                }
                writer.Indent--;
            }
            writer.WriteLineNoTabs("");

            writer.Indent++;

            string[] mainDoc = null;
            foreach (var item in list)
            {
                if (item.mainDoc.Count > 0)
                {
                    mainDoc = item.mainDoc.ToArray();
                    break;
                }
            }

            if (mainDoc != null)
            {
                foreach (var item in list[0].mainDoc)
                {
                    writer.WriteLine(item);
                }
            }
            #if DEBUG
            else
            {
                writer.WriteLine("No doc for this code found.");
            }
            #endif
            if (parameterDocs.Count > 0)
            {
                WriteParameters(writer, parameterDocs);
            }
            writer.Indent--;
        }
        private static void WriteCodeTemplates(IList<DocCode> list, 
            IndentedTextWriter indentedWriter, 
            IList<CodeTemplate> templates)
        {
            var parameterDocs = new Dictionary<string, List<string>>(
                StringComparer.CurrentCultureIgnoreCase);

            var templatesSortedByGame = new Dictionary<string, List<CodeTemplate>>();

            for (int i = 0; i < templates.Count; i++)
            {
                string key = list[i].languages.ToHumanString();
                List<CodeTemplate> tempList = templatesSortedByGame.GetOldOrSetNew(key);
                tempList.Add(templates[i]);

                foreach (var parameter in templates[i])
                {
                    List<string> values = parameterDocs.GetOldOrSetNew(parameter.name);
                    values.AddRange(list[i].parameterDocs[parameter.name]);
                }
            }

            foreach (var item in templatesSortedByGame)
            {
                indentedWriter.WriteLine(item.Key + ":");
                indentedWriter.Indent++;
                foreach (var template in item.Value)
                {
                    CodeTemplate.WriteDoc(indentedWriter, template);
                }
                indentedWriter.Indent--;
            }

            indentedWriter.Indent++;

            List<string> mainDoc = new List<string>();
            foreach (var item in list)
            {
                if (item.mainDoc.Count > 0)
                {
                    mainDoc.AddRange(item.mainDoc);
                    break;
                }
            }

            if (mainDoc.Count > 0)
            {
                indentedWriter.WriteLineNoTabs("");
                foreach (var item in mainDoc)
                {
                    indentedWriter.WriteLine(item);
                }
            }
            #if DEBUG
            else
            {
                indentedWriter.WriteLine("No doc for this code found.");
            }
            #endif
            if (parameterDocs.Count > 0)
            {
                WriteParameters(indentedWriter, parameterDocs);
            }
            indentedWriter.Indent--;
        }