Esempio n. 1
0
        public static void Write(IfStatement ifStatement, IndentedStreamWriter writer)
        {
            if (ifStatement.Ifs.Any())
            {
                If @if = ifStatement.Ifs.First();
                IEnumerable <If> elseIfs = ifStatement.Ifs.Skip(1);

                writer.WriteLine($"if ({@if.Condition})");
                writer.OpenBrackets();
                @if.Body(new BodyWriter(writer));
                writer.CloseBrackets();

                foreach (If elseIf in elseIfs)
                {
                    writer.WriteLine($"if ({elseIf.Condition})");
                    writer.OpenBrackets();
                    elseIf.Body(new BodyWriter(writer));
                    writer.CloseBrackets();
                }
            }
            else
            {
                writer.WriteLine("if (false)");
                writer.OpenBrackets();
                writer.CloseBrackets();
            }

            if (ifStatement.ElseBody is { })
Esempio n. 2
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)
Esempio n. 3
0
        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);
        }
Esempio n. 4
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 { })
Esempio n. 5
0
 public UsingWriter(IndentedStreamWriter writer, IEnumerable <string> usings) : base(writer) => _usings = new HashSet <string>(usings);
Esempio n. 6
0
 public BodyWriter(IndentedStreamWriter writer) => _writer = writer;
Esempio n. 7
0
 public PropertyWriter(IndentedStreamWriter writer, IEnumerable <Property> properties) : this(writer) => _properties.AddRange(properties);
Esempio n. 8
0
 public PropertyWriter(IndentedStreamWriter writer) : base(writer)
 {
 }
Esempio n. 9
0
 protected BaseWriter(IndentedStreamWriter writer) => _writer = writer;
Esempio n. 10
0
 public FieldWriter(IndentedStreamWriter writer, IEnumerable <Field> fields) : this(writer) => _fields.AddRange(fields);
Esempio n. 11
0
 public FieldWriter(IndentedStreamWriter writer) : base(writer)
 {
 }
Esempio n. 12
0
 public ConstructorWriter(IndentedStreamWriter writer, string name) : base(writer) => _name = name;
Esempio n. 13
0
        Dispose(true);    // TODO: uncomment the following line if the finalizer is overridden above.// GC.SuppressFinalize(this);

        #endregion

        public static void NopWriter(IndentedStreamWriter writer)
        {
        }