예제 #1
0
        public static async Task WriteAsync(Class c, Stream stream)
        {
            var writer = new IndentedStreamWriter(stream);

            var usingWriter     = new UsingWriter(writer);
            var namespaceWriter = new NamespaceWriter(writer, c.Namespace);

            BaseWriter[] bodyWriters = new BaseWriter[]
            {
                new FieldWriter(writer, c.Fields),
                new ConstructorWriter(writer, c.ClassName, c.Ctors),
                new PropertyWriter(writer, c.Properties),
                new MethodWriter(writer, c.Methods)
            };

            foreach (string?u in c.Usings)
            {
                usingWriter.AddUsing(u);
            }

            if (usingWriter.Make())
            {
                await writer.WriteLineAsync();
            }

            var classDescription = new List <string>();

            if (c.Accessibility.HasValue)
            {
                classDescription.Add(c.Accessibility.Value.ToSharpieString());
            }
            if (c.Static)
            {
                classDescription.Add("static");
            }
            if (c.Partial)
            {
                classDescription.Add("partial");
            }

            classDescription.Add("class");
            classDescription.Add(c.ClassName);

            namespaceWriter.Begin();
            await writer.WriteLineAsync(string.Join(" ", classDescription) + c.GetInheritance());

            await writer.WriteLineAsync("{");

            writer.IndentationLevel++;

            BaseWriter?prevWriter         = null;
            bool       prevWroteSomething = false;

            foreach (BaseWriter bodyWriter in bodyWriters)
            {
                if (prevWriter is { } && prevWroteSomething)
예제 #2
0
파일: IfWriter.cs 프로젝트: mztikk/Sharpie
        public static async Task WriteAsync(If @if, IndentedStreamWriter writer)
        {
            await writer.WriteLineAsync($"if ({@if.Condition})");

            await writer.WriteLineAsync("{").ConfigureAwait(false);

            writer.IndentationLevel++;

            var bodyWriter = new BodyWriter(writer);

            @if.Body(bodyWriter);

            writer.IndentationLevel--;
            await writer.WriteLineAsync("}").ConfigureAwait(false);
        }
예제 #3
0
        public static async Task WriteAsync(SwitchCaseStatement switchCaseStatement, IndentedStreamWriter writer)
        {
            await writer.WriteLineAsync($"switch ({switchCaseStatement.Expression})");

            await writer.WriteLineAsync("{");

            writer.IndentationLevel++;

            var bodyWriter = new BodyWriter(writer);

            foreach (CaseStatement @case in switchCaseStatement.CaseStatements)
            {
                await writer.WriteLineAsync($"case {@case.Case}:");

                writer.IndentationLevel++;
                @case.Body(bodyWriter);
                writer.IndentationLevel--;
            }

            if (switchCaseStatement.DefaultCaseBody is { })