-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathModelGenTool.cs
More file actions
107 lines (96 loc) · 3.11 KB
/
Copy pathModelGenTool.cs
File metadata and controls
107 lines (96 loc) · 3.11 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TextTemplating;
using SystemUtils.Tools;
namespace modelgen
{
public class ModelGenTool
{
[ToolArgDefault]
public string SourceFilename { get; set; }
public string RootNodeTypeName { get; set; }
public bool? GenerateLinq { get; set; }
public bool? GenerateEnum { get; set; }
public bool? GenerateProperties { get; set; }
public string Namespace { get; set; }
public List<string> Using { get; set; }
public bool Help { get; set; }
public void Execute()
{
new Tool
{
Filename = @"C:\Projects\c2j\src\modelgen\bin\Debug\modelgen.exe",
Args = ToolArgsGenerator.Generate(this),
}.Run();
}
public void Run()
{
Generator = new ModelGen
{
SourceText = SourceText,
SourceFilename = SourceFilename,
GenerateEnum = GenerateEnum.GetValueOrDefault(true),
GenerateLinq = GenerateLinq.GetValueOrDefault(true),
GenerateProperties = GenerateProperties.GetValueOrDefault(true),
RootNodeTypeName = RootNodeTypeName,
Namespace = Namespace,
};
if (OutputFilename == null)
Generator.OutputFilename = SourceFilename.ToFsPath().ChangeExtension(".generated.cs");
if (Using != null)
Generator.Usings.AddRange(Using);
Generator.Run();
}
internal ModelGen Generator;
public string SourceText { get; set; }
public string OutputFilename { get; set; }
}
static class Extensions2
{
public static T ReflectionGetPropertyValue<T>(this object obj, string name)
{
return (T)obj.GetType().GetProperty(name).GetValue(obj, null);
}
public static T ReflectionInvoke<T>(this object obj, string name, params object[] args)
{
return (T)obj.GetType().GetMethods().Where(t => t.Name == name && t.GetParameters().Length == args.Length).First().Invoke(obj, args);
}
public static void ReflectionInvoke(this object obj, string name, params object[] args)
{
obj.ReflectionInvoke<object>(name, args);
}
}
class ReflectionTextTemplating
{
public ReflectionTextTemplating(object obj)
{
Obj = obj;
}
object Obj;
public void WriteLine(string p)
{
Obj.ReflectionInvoke("WriteLine", p);
}
}
class ReflectionTextTemplatingHost
{
public ReflectionTextTemplatingHost(object obj)
{
Obj = obj;
}
object Obj;
public string TemplateFile
{
get
{
return Obj.ReflectionGetPropertyValue<string>("TemplateFile");
}
}
}
}