-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMslnConf.cs
84 lines (82 loc) · 3.27 KB
/
MslnConf.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Collections;
namespace CodeCreator
{
public class MslnConf
{
public string MslnPath { set; get; }
public Hashtable ht = (Hashtable)DataTransfer.data;
public List<TemplateItem> tmpItems { set; get; }
public MslnConf(string mslnPath)
{
this.MslnPath = mslnPath;
Init();
}
private void Init()
{
List<TemplateItem> list = new List<TemplateItem>();
TemplateItem template = null;
bool flag = false;
string[] lines = File.ReadAllLines(MslnPath);
string tablename = ht["TableName"].ToString();
string TableNamePrefix = tablename.ToUpper().Substring(0, 1) + tablename.Substring(1);
string TableNameClearPrefix = tablename.Contains("_") ? (tablename.IndexOf('_') > tablename.Length - 1) ? tablename : tablename.Substring(tablename.IndexOf('_') + 1) : tablename;
char[] chars = TableNameClearPrefix.ToLower().ToCharArray();
chars[0] = chars[0].ToString().ToUpper().First();
string TableNameClearPrefixFormat = new string(chars);
foreach (var item in lines)
{
string tmp = item;
tmp = tmp.Trim().Trim('\t');
if (tmp.StartsWith("//"))
{
continue;
}
if (tmp.StartsWith("#Item_Start"))
{
template = new TemplateItem();
list.Add(template);
flag = true;
}
else if (tmp.StartsWith("#Item_End"))
{
flag = false;
}
else
{
if (flag)
{
if (tmp.StartsWith("#Path"))
{
template.Path = "TmpSolutions/" + tmp.Substring("#Path".Length).Trim('=');
}
else if (tmp.StartsWith("#OutName"))
{
template.OutName = tmp.Substring("#OutName".Length).Trim('=').Replace("#TableName#", ht["TableName"].ToString()).Replace("#TableNameClearPrefixFormat#", TableNameClearPrefixFormat).Replace("#TableNameClearPrefix#", TableNameClearPrefix).Replace("#TableNamePrefix#", TableNamePrefix);
}
else if (tmp.StartsWith("#ClassFullName"))
{
template.ClassFullName = tmp.Substring("#ClassFullName".Length).Trim('=');
}
else if (tmp.StartsWith("#CreateMethod"))
{
template.CreateMethod = tmp.Substring("#CreateMethod".Length).Trim('=');
}
}
}
}
tmpItems = list;
}
public class TemplateItem
{
public string Path { set; get; }
public string OutName { set; get; }
public string ClassFullName { set; get; }
public string CreateMethod { set; get; }
}
}
}