Ejemplo n.º 1
0
        private void WriteDictionary(CodeBlock block, Dictionary <string, Value> A)
        {
            switch (format)
            {
            case ValueOutputFormat.SingleLine:
                block.Append("{");
                A.ForEach(
                    kvp =>
                {
                    block.Append($"{kvp.Key} = ");
                    kvp.Value.BuildCode(block);
                },
                    _ => block.Append(",")
                    );

                block.Append("}");
                break;

            default:
                block.Begin();

                A.ForEach(
                    kvp =>
                {
                    block.AppendLine();
                    block.Append($"{kvp.Key} = ");
                    kvp.Value.BuildCode(block);
                },
                    _ => block.Append(",")
                    );

                block.End();
                break;
            }
        }
Ejemplo n.º 2
0
        private void OutputExpressions(CodeBlock block)
        {
            switch (Format)
            {
            case ValueOutputFormat.SingleLine:
                block.Append(" { ");
                expressions.ForEach(
                    expr =>
                {
                    block.Append(expr);
                },
                    _ => block.Append(", ")
                    );

                block.Append(" }");
                break;

            default:
                block.Begin();
                expressions.ForEach(
                    expr =>
                {
                    block.AppendLine();
                    block.Append(expr);
                },
                    _ => block.Append(",")
                    );

                block.End();
                break;
            }
        }
Ejemplo n.º 3
0
        private void WriteDictionary(CodeBlock block, Dictionary <object, object> dict)
        {
            switch (Format)
            {
            case ValueOutputFormat.SingleLine:
                block.Append("{");
                dict.ForEach(
                    kvp =>
                {
                    block.Append($"[{kvp.Key}] = ");
                    NewValue(kvp.Value).BuildBlock(block);
                },
                    _ => block.Append(",")
                    );

                block.Append("}");
                break;

            default:
                block.Begin();

                dict.ForEach(
                    kvp =>
                {
                    block.AppendLine();
                    block.Append($"[{kvp.Key}] = ");
                    NewValue(kvp.Value).BuildBlock(block);
                },
                    _ => block.Append(",")
                    );

                block.End();
                break;
            }
        }
Ejemplo n.º 4
0
        protected override void BuildBlock(CodeBlock block)
        {
            base.BuildBlock(block);

            if (Comment?.Alignment == Alignment.Top)
            {
                block.AppendFormat(Comment.ToString());
                Comment.Clear();
            }

            if (Expression != null)
            {
                block.AppendFormat("{0}{1}", $"{Signature} => {Expression};", Comment);
            }
            else if (Gets.Count == 0 && Sets.Count == 0)
            {
                if (value != null)
                {
                    block.AppendFormat("{0}{1}", $"{Signature} {{ {get}; {set}; }} = {value};", Comment);
                }
                else
                {
                    block.AppendFormat("{0}{1}", $"{Signature} {{ {get}; {set}; }}", Comment);
                }
            }
            else if (!IsLambda)
            {
                block.AppendLine(Signature + Comment);
                block.Begin();
                if (Gets.Count != 0)
                {
                    block.AppendLine(get);
                    block.AddWithBeginEnd(Gets);
                }

                if (Sets.Count != 0)
                {
                    block.AppendLine(set);
                    block.AddWithBeginEnd(Sets);
                }

                block.End();
            }
            else
            {
                block.AppendLine(Signature + Comment);
                if (Gets.Count != 0)
                {
                    Lambda(block, get, Gets);
                }

                if (Sets.Count != 0)
                {
                    Lambda(block, set, Sets);
                }
            }

            return;
        }
Ejemplo n.º 5
0
        private void WriteArrayValue(CodeBlock block, Array A, int columnNumber)
        {
            Type ty = Type.GetElementType();

            if (ty != null && ty.IsPrimitive)
            {
                if (A.Length < 30)
                {
                    format = ValueOutputFormat.SingleLine;
                }
                else if (A.Length < 100)
                {
                    format       = ValueOutputFormat.Wrap;
                    columnNumber = 10;
                }
                else
                {
                    format       = ValueOutputFormat.Wrap;
                    columnNumber = 20;
                }
            }

            switch (format)
            {
            case ValueOutputFormat.SingleLine:
                block.Append("{");
                A.OfType <object>().ForEach(
                    x =>
                {
                    NewValue(x).BuildCode(block);
                },
                    _ => block.Append(",")
                    );

                block.Append("}");
                break;



            case ValueOutputFormat.Wrap:
                block.Begin();
                for (int i = 0; i < A.Length; i++)
                {
                    if (i % columnNumber == 0)
                    {
                        block.AppendLine();
                    }

                    if (i != 0 && i % (columnNumber * 10) == 0)         //add empty line every 10 lines
                    {
                        block.AppendLine();
                    }

                    Value item = NewValue(A.GetValue(i));
                    item.BuildCode(block);

                    if (i != A.Length - 1)
                    {
                        block.Append(",");
                    }
                }

                block.End();
                break;

            default:
                block.Begin();

                for (int i = 0; i < A.Length; i++)
                {
                    if (i != 0 && i % columnNumber == 0)
                    {
                        block.AppendLine();
                    }

                    block.AppendLine();
                    Value item = NewValue(A.GetValue(i));
                    item.BuildCode(block);

                    if (i != A.Length - 1)
                    {
                        block.Append(",");
                    }
                }

                block.End();
                break;
            }
        }