Пример #1
0
        private void GenerateOutputForClass(ClassInfo classInfo, StreamWriter streamWriter, bool subClass = false,
                                            int tabCount = 0)
        {
            if (!subClass)
            {
                var wrapperClassInfo = classInfo.GenerateWrapper(classInfo.Name, classInfo.Name + "Base");
                classInfo.Name += "Base";
                classInfo.Generate();

                foreach (var item in classInfo.Usings)
                {
                    streamWriter.WriteLine(item);
                }

                if (wrapperClassInfo.Attributes.Any(x => x.AttributeType == typeof(TagClassAttribute)))
                {
                    streamWriter.WriteLine();
                    streamWriter.WriteLine("namespace Moonfish.Tags".Tab(ref tabCount));
                    streamWriter.WriteLine("{".Tab(ref tabCount));
                    var @class =
                        wrapperClassInfo.Attributes.First(x => x.AttributeType == typeof(TagClassAttribute))
                        .Parameters[0
                        ].Trim('"');
                    streamWriter.WriteLine(
                        string.Format("public partial struct {0}", typeof(TagClass).Name).Tab(ref tabCount));
                    streamWriter.WriteLine("{".Tab(ref tabCount));

                    var tagClass  = (TagClass)@class;
                    var titleCase = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(tagClass.ToTokenString());
                    streamWriter.WriteLine(
                        string.Format(@"public static readonly {0} {1} = ({0})""{2}"";", typeof(TagClass).Name,
                                      titleCase, @class).Tab(ref tabCount));
                    streamWriter.WriteLine("};".Tab(ref tabCount));
                    streamWriter.WriteLine("};".Tab(ref tabCount));
                }

                streamWriter.WriteLine();
                streamWriter.WriteLine(classInfo.Namespace.ToString().Tab(ref tabCount));
                streamWriter.WriteLine("{".Tab(ref tabCount));

                GenerateOutputForSubclass(wrapperClassInfo, streamWriter, tabCount);
            }
            classInfo.Attributes.ForEach(x => streamWriter.WriteLine(x.ToString().Tab(ref tabCount)));
            streamWriter.WriteLine(classInfo.ClassDeclaration.Tab(ref tabCount));
            streamWriter.WriteLine("{".Tab(ref tabCount));

            if (!subClass)
            {
                classInfo.Name =
                    classInfo.Name.Remove(classInfo.Name.LastIndexOf("Base", StringComparison.Ordinal), 4);
            }

            foreach (var item in classInfo.Fields)
            {
                tabCount = ProcessLines(streamWriter, tabCount, item);
            }

            foreach (var item in classInfo.Properties)
            {
                tabCount = ProcessLines(streamWriter, tabCount, item);
            }

            foreach (var item in classInfo.Constructors)
            {
                tabCount = ProcessLines(streamWriter, tabCount, item);
            }

            foreach (var item in classInfo.Methods)
            {
                tabCount = ProcessLines(streamWriter, tabCount, item);
            }

            foreach (var item in classInfo.EnumDefinitions)
            {
                tabCount = ProcessLines(streamWriter, tabCount, item);
            }

            foreach (var item in classInfo.ClassDefinitions)
            {
                item.Generate();
                GenerateOutputForSubclass(item, streamWriter, tabCount);
            }

            streamWriter.WriteLine("};".Tab(ref tabCount));

            if (!subClass)
            {
                streamWriter.WriteLine("}".Tab(ref tabCount));
            }
            streamWriter.Flush();
        }
Пример #2
0
        private void GenerateOutputForClass(ClassInfo classInfo, StreamWriter streamWriter, bool subClass = false, int tabCount = 0)
        {
            if (!subClass)
            {
                var wrapperClassInfo = classInfo.GenerateWrapper(classInfo.Value.Name, classInfo.Value.Name + "Base");
                classInfo.Value.Name += "Base";
                classInfo.Generate();

                foreach (var item in classInfo.Usings)
                {
                    streamWriter.WriteLine(item);
                }
                streamWriter.WriteLine();
                streamWriter.WriteLine(classInfo.NamespaceDeclaration.Tab(ref tabCount));
                streamWriter.WriteLine("{".Tab(ref tabCount));

                GenerateOutputForSubclass(wrapperClassInfo, streamWriter, tabCount);
            }
            classInfo.Attributes.ForEach(x => streamWriter.WriteLine(x.ToString().Tab(ref tabCount)));
            streamWriter.WriteLine(classInfo.ClassDeclaration.Tab(ref tabCount));
            streamWriter.WriteLine("{".Tab(ref tabCount));

            if (!subClass)
            {
                classInfo.Value.Name = classInfo.Value.Name.Remove(classInfo.Value.Name.LastIndexOf("Base"), 4);
            }

            foreach (var item in classInfo.Fields)
            {
                tabCount = ProcessLines(streamWriter, tabCount, item);
            }

            foreach (var item in classInfo.Constructors)
            {
                tabCount = ProcessLines(streamWriter, tabCount, item);
            }

            foreach (var item in classInfo.Methods)
            {
                tabCount = ProcessLines(streamWriter, tabCount, item);
            }

            foreach (var item in classInfo.EnumDefinitions)
            {
                tabCount = ProcessLines(streamWriter, tabCount, item);
            }

            foreach (var item in classInfo.ClassDefinitions)
            {
                item.Generate();
                GenerateOutputForSubclass(item, streamWriter, tabCount);
            }

            streamWriter.WriteLine("};".Tab(ref tabCount));

            if (!subClass)
            {
                streamWriter.WriteLine("}".Tab(ref tabCount));
            }
            streamWriter.Flush();
        }