forked from reinforced/Reinforced.Typings
/
ExportContext.cs
209 lines (181 loc) · 6.04 KB
/
ExportContext.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
using System;
using System.Collections.Generic;
using System.Reflection;
using Reinforced.Typings.Exceptions;
using Reinforced.Typings.Fluent;
using Reinforced.Typings.Xmldoc;
namespace Reinforced.Typings
{
/// <summary>
/// TsExport exporting settings
/// </summary>
public class ExportContext
{
private Action<ConfigurationBuilder> _configurationMethod;
private string _documentationFilePath;
private bool _hierarchical;
private bool _isLocked;
private Assembly[] _sourceAssemblies;
private string _targetDirectory;
private string _targetFile;
private IFilesOperations _fileOperations;
/// <summary>
/// File I/O operations frontend
/// </summary>
public IFilesOperations FileOperations
{
get { return _fileOperations; }
set
{
_fileOperations = value;
_fileOperations.Context = this;
}
}
/// <summary>
/// Instantiates new ExportContext instance (only for testing/integration)
/// </summary>
public ExportContext(IFilesOperations fileOperationsServiceOverride = null)
{
Warnings = new List<RtWarning>();
_fileOperations = fileOperationsServiceOverride;
if (_fileOperations == null) _fileOperations = new FilesOperations();
_fileOperations.Context = this;
Global = new GlobalParameters();
Location = new Location(this);
Project = new ProjectBlueprint();
}
/// <summary>
/// Identifies where current export is performed in terms of AST.
/// Context.Location could be used to conditionally add members to different places of generated source code
/// </summary>
public Location Location { get; private set; }
/// <summary>
/// The assemblies to extract typings from.
/// Important! TsExporter do not perform any job for loading assemblies. It is left upon a calling side.
/// That is because loading assemblies is highly dependent on calling side's AppDomain.
/// TsExporter shouldnt handle all this shit
/// </summary>
public Assembly[] SourceAssemblies
{
get { return _sourceAssemblies; }
set
{
if (_isLocked) return;
_sourceAssemblies = value;
}
}
/// <summary>
/// True to create project hierarchy in target folder.
/// False to store generated typings in single file
/// </summary>
public bool Hierarchical
{
get { return _hierarchical; }
set
{
if (_isLocked) return;
_hierarchical = value;
}
}
/// <summary>
/// Target directory where to store generated typing files.
/// This parameter is not used when Hierarcy is false
/// </summary>
public string TargetDirectory
{
get { return _targetDirectory; }
set
{
if (_isLocked) return;
_targetDirectory = value;
}
}
/// <summary>
/// Target file where to store generated sources.
/// This parameter is not used when Hierarchy is true
/// </summary>
public string TargetFile
{
get { return _targetFile; }
set
{
if (_isLocked) return;
_targetFile = value;
}
}
/// <summary>
/// Path to assembly's XMLDOC file
/// </summary>
public string DocumentationFilePath
{
get { return _documentationFilePath; }
set
{
if (_isLocked) return;
_documentationFilePath = value;
}
}
/// <summary>
/// Fluent configuration method
/// </summary>
public Action<ConfigurationBuilder> ConfigurationMethod
{
get { return _configurationMethod; }
set
{
if (_isLocked) return;
_configurationMethod = value;
}
}
/// <summary>
/// Documentation manager
/// </summary>
public DocumentationManager Documentation { get; internal set; }
/// <summary>
/// Warnings that should be displayed after build.
/// Feel free to add messages from generators here.
/// </summary>
public List<RtWarning> Warnings { get; private set; }
#region Internals
/// <summary>
/// Blueprint of type currently being exported
/// </summary>
public TypeBlueprint CurrentBlueprint
{
get
{
if (Location._typesStack.Count == 0) return null;
return Location._typesStack.Peek();
}
}
/// <summary>
/// There is a case when you are exporting base class as interface. It may lead to some unusual handling of generation,
/// so I'm using this property to denote such cases and fix it in-place
/// </summary>
internal bool SpecialCase { get; set; }
internal void Lock()
{
_isLocked = true;
Global.Lock();
}
internal void Unlock()
{
_isLocked = false;
Global.Unlock();
}
internal string CurrentNamespace { get; set; }
/// <summary>
/// Global generation parameters
/// </summary>
public GlobalParameters Global { get; private set; }
/// <summary>
/// Generators cache
/// </summary>
public GeneratorManager Generators { get; internal set; }
/// <summary>
/// Project blueprint
/// </summary>
public ProjectBlueprint Project { get; private set; }
#endregion
}
}