예제 #1
0
        public void WriteCode(StringBuilder strBldr)
        {
            var idnt     = useIndent ? indentCount : 0;
            var nextIdnt = useIndent ? idnt + 1 : 0;

            var idntStr     = CodeGeneratorUtil.CreateIndent(idnt);
            var nextIdntStr = CodeGeneratorUtil.CreateIndent(nextIdnt);

            strBldr.Append(accessModifier.ToAccessModifierStr().Indent(idntStr));
            strBldr.Append(" ");

            if (isStatic)
            {
                strBldr.Append(CodeGeneratorConst.STATIC_STR);
                strBldr.Append(" ");
            }

            strBldr.Append(CodeGeneratorConst.CLASS_STR);
            strBldr.Append(" ");

            strBldr.Append(name);
            strBldr.AppendLine();

            strBldr.AppendLine("{".Indent(idntStr));
            {
                var iter = _methodCodes.GetEnumerator();
                while (iter.MoveNext())
                {
                    var curMethod = iter.Current;
                    curMethod.WriteCode(strBldr);
                }
            }
            strBldr.AppendLine("}".Indent(idntStr));
        }
예제 #2
0
        public void WriteCode(StringBuilder strBldr)
        {
            var idnt     = useIndent ? indentCount : 0;
            var nextIdnt = useIndent ? idnt + 1 : 0;

            var idntStr     = CodeGeneratorUtil.CreateIndent(idnt);
            var nextIdntStr = CodeGeneratorUtil.CreateIndent(nextIdnt);

            strBldr.AppendLine(code.Indent(idntStr));

            var iter = _lineCodes.GetEnumerator();

            while (iter.MoveNext())
            {
                var curLine = iter.Current;
                curLine.WriteCode(strBldr);
            }
        }
예제 #3
0
        public StringBuilder BuildCode()
        {
            var strBldr  = new StringBuilder();
            var idnt     = useIndent ? indentCount : 0;
            var nextIdnt = useIndent ? idnt + 1 : 0;

            var idntStr     = CodeGeneratorUtil.CreateIndent(idnt);
            var nextIdntStr = CodeGeneratorUtil.CreateIndent(nextIdnt);

            // Write Usings
            foreach (var @using in _usings)
            {
                strBldr.AppendLine($"using {@using};".Indent(idntStr));
            }

            strBldr.AppendLine();

            // write namespace
            bool hasNamespace = !string.IsNullOrEmpty(namespaceName);

            if (hasNamespace)
            {
                strBldr.AppendLine($"namespace {namespaceName}".Indent(idntStr));
                strBldr.AppendLine("{".Indent(idntStr));
            }

            {
                var iter = _classCodes.GetEnumerator();
                while (iter.MoveNext())
                {
                    var classCode = iter.Current;

                    classCode.WriteCode(strBldr);
                }
            }

            if (hasNamespace)
            {
                strBldr.AppendLine("}".Indent(idntStr));
            }

            return(strBldr);
        }