Esempio n. 1
0
        /// <summary>
        /// 格式化输出类代码。
        /// </summary>
        /// <returns>返回代码字符串。</returns>
        public override string ToString()
        {
            var header = new StringBuilder();

            header.Append("namespace ").AppendLine(Namespace);
            header.AppendLine("{");
            var builder = new StringBuilder();

            if (!string.IsNullOrEmpty(Desc))
            {
                builder.AppendLine("    /// <summary>");
                builder.Append("    /// ").Append(Desc).AppendLine("。");
                builder.AppendLine("    /// </summary>");
            }

            builder.Append("    public class ").Append(Name.Normalize());
            if (Base != null && Base.Count > 0)
            {
                builder.Append(" : ");
                var baseClass = Base.FirstOrDefault(x => x.StartsWith('I'));
                if (baseClass != null)
                {
                    Base.Remove(baseClass);
                    Base.Insert(0, baseClass);
                }

                builder.Append(string.Join(", ", Base));
            }

            builder.AppendLine();
            builder.AppendLine("    {");
            foreach (var property in Props)
            {
                property.Class = this;
                builder.AppendLine(property.ToString());
            }
            builder.AppendLine("    }");
            builder.AppendLine("}");

            if (Using != null && Using.Count > 0)
            {
                foreach (var @using in Using.Distinct())
                {
                    header.AppendLine($"    using {@using};");
                }

                header.AppendLine();
            }

            builder.Insert(0, header);
            return(builder.ToString());
        }