Beispiel #1
0
        private string ProcessClass(ClassGenInfo classGenInfo, Dictionary <INamedTypeSymbol, ClassGenInfo> map)
        {
            var classSymbol = classGenInfo.m_symbol;

            var writer = new IndentedTextWriter(new StringWriter(), "    ");

            writer.WriteLine("using System;");
            writer.WriteLine("using System.IO;");
            writer.WriteLine("using System.Collections.Generic;");
            writer.WriteLine("using StackXML;");
            writer.WriteLine("using StackXML.Str;");
            writer.WriteLine();

            var scope = new NestedScope(classSymbol);

            scope.Start(writer);

            writer.Write(NestedScope.GetClsString(classSymbol));
            if (classSymbol.BaseType == null || classSymbol.BaseType.ToString() == "object") // can it be null... idk
            {
                writer.Write(" : IXmlSerializable");
            }
            writer.WriteLine();
            writer.WriteLine("{");
            writer.Indent++;

            if (classGenInfo.m_className != null)
            {
                writer.WriteLine("public override ReadOnlySpan<char> GetNodeName()");
                writer.WriteLine("{");
                writer.Indent++;
                writer.WriteLine($"return \"{classGenInfo.m_className}\";");
                writer.Indent--;
                writer.WriteLine("}");
            }

            if (classGenInfo.m_fields.Count > 0)
            {
                WriteAttrParseMethod(writer, classGenInfo);
                WriteAttSerializeMethod(writer, classGenInfo);
            }

            if (classGenInfo.m_bodies.Count > 0)
            {
                WriteParseBodyMethods(writer, classGenInfo, map);
                WriteSerializeBodyMethod(writer, classGenInfo);
            }

            writer.Indent--;
            writer.WriteLine("}"); // end class
            scope.End(writer);

            return(writer.InnerWriter.ToString());
        }
Beispiel #2
0
        private string ProcessClass(INamedTypeSymbol classSymbol, ClassGenInfo classGenInfo, Dictionary <INamedTypeSymbol, ClassGenInfo> classes)
        {
            var writer = new IndentedTextWriter(new StringWriter(), "    ");

            writer.WriteLine("using StackXML;");
            writer.WriteLine("using StackXML.Str;");
            writer.WriteLine();

            var scope = new NestedScope(classSymbol);

            scope.Start(writer);
            writer.WriteLine(NestedScope.GetClsString(classSymbol));
            writer.WriteLine("{");
            writer.Indent++;

            WriteDeserializeMethod(writer, classGenInfo, classes);
            WriteSerializeMethod(writer, classGenInfo, classes);

            writer.Indent--;
            writer.WriteLine("}");
            scope.End(writer);

            return(writer.InnerWriter.ToString());
        }