private static CodeGenerator BuildBuildMethod(CodeGenerator cb, BuilderModel model)
        {
            cb.AppendLine("public ", model.OriginalClassName, " Build()");
            cb.OpenBlock();
            cb.Append("return new ", model.OriginalClassName, "()");
            if (model.Properties.Count == 0)
            {
                cb.AppendLine(";");
            }
            else
            {
                cb.AppendLine();
                cb.OpenBlock();
                bool first = true;
                foreach (var property in model.Properties)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        cb.AppendLine(",");
                    }

                    BuildPropertyInit(cb, property);
                }

                cb.CloseBlock(";");
            }

            cb.CloseBlock();
            return(cb);
        }
        private static CodeGenerator BuildConstructor(CodeGenerator cb, BuilderModel model)
        {
            cb.AppendLine("public ", model.BuilderClassName, "()");
            cb.OpenBlock();
            foreach (var property in model.Properties)
            {
                BuildFieldAssignment(cb, property);
            }

            cb.CloseBlock();
            return(cb);
        }
        public string Generate(BuilderModel model)
        {
            var cb = new CodeGenerator();

            BuildClassDeclaration(cb, model.BuilderClassName);
            cb.OpenBlock();

            BuildFields(cb, model.Properties);
            cb.AppendLine();
            BuildConstructor(cb, model);
            cb.AppendLine();
            BuildWiths(cb, model);
            cb.AppendLine();
            BuildBuildMethod(cb, model);

            cb.CloseBlock();

            return(cb.ToString());
        }
        private static CodeGenerator BuildWiths(CodeGenerator cb, BuilderModel model)
        {
            bool first = true;

            foreach (var property in model.Properties)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    cb.AppendLine();
                }

                BuildWith(cb, property, model.BuilderClassName);
            }

            return(cb);
        }