コード例 #1
0
ファイル: ClassGenerator.cs プロジェクト: bizcad/CsvToClass
        private string FormatClass(string nameSpace, string className)
        {
            var rows = ReadFileIntoList(_inputFile);

            StringBuilder sb = new StringBuilder();

            // write the class heading
            sb.AppendLine("using System;");
            sb.AppendLine();
            sb.Append("namespace ");
            sb.AppendLine(nameSpace);
            sb.AppendLine("{");
            sb.Append("    public class ");
            sb.AppendLine(className);
            sb.AppendLine("    {");
            sb.AppendLine("        public int Id { get; set; }");

            var propertySpecicationList = new CsvColumnTyper().ParseColumns(ref rows);
            foreach (var p in propertySpecicationList)
            {
                
                sb.Append(string.Format("        public {0}", p.ColumnType));
                if (p.Nullable)
                    sb.Append("?");
                sb.AppendLine(string.Format(" {0} {1} get; set; {2}", IllegalCharactersFilter.FilterIdentifier(p.ColumnName), "{", "}"));
            }

            sb.AppendLine("    }");
            sb.AppendLine("}");

            return sb.ToString();
        }
コード例 #2
0
        private string FormatClass(string nameSpace, string className)
        {
            var rows = ReadFileIntoList(_inputFile);

            StringBuilder sb = new StringBuilder();

            // write the class heading
            sb.AppendLine("using System;");
            sb.AppendLine();
            sb.Append("namespace ");
            sb.AppendLine(nameSpace);
            sb.AppendLine("{");
            sb.Append("    public class ");
            sb.AppendLine(className);
            sb.AppendLine("    {");
            sb.AppendLine("        public int Id { get; set; }");

            var propertySpecicationList = new CsvColumnTyper().ParseColumns(ref rows);

            foreach (var p in propertySpecicationList)
            {
                sb.Append(string.Format("        public {0}", p.ColumnType));
                if (p.Nullable)
                {
                    sb.Append("?");
                }
                sb.AppendLine(string.Format(" {0} {1} get; set; {2}", IllegalCharactersFilter.FilterIdentifier(p.ColumnName), "{", "}"));
            }

            sb.AppendLine("    }");
            sb.AppendLine("}");

            return(sb.ToString());
        }