@@ -31,6 +31,10 @@ public class GenAPITask : BuildTask
31
31
"// the code is regenerated.\r \n " +
32
32
"// </auto-generated>\r \n " +
33
33
"//------------------------------------------------------------------------------\r \n " ;
34
+
35
+ private WriterType _writerType ;
36
+ private SyntaxWriterType _syntaxWriterType ;
37
+ private DocIdKinds _docIdKinds = Cci . Writers . DocIdKinds . All ;
34
38
35
39
/// <summary>
36
40
/// Path for an specific assembly or a directory to get all assemblies.
@@ -62,17 +66,29 @@ public class GenAPITask : BuildTask
62
66
/// <summary>
63
67
/// Specify the writer type to use. Legal values: CSDecl, DocIds, TypeForwards, TypeList. Default is CSDecl.
64
68
/// </summary>
65
- public WriterType WriterType { get ; set ; }
69
+ public string WriterType
70
+ {
71
+ get => _writerType . ToString ( ) ;
72
+ set => _writerType = string . IsNullOrWhiteSpace ( value ) ? default : ( WriterType ) Enum . Parse ( typeof ( WriterType ) , value , true ) ;
73
+ }
66
74
67
75
/// <summary>
68
76
/// Specific the syntax writer type. Only used if the writer is CSDecl. Legal values: Text, Html, Xml. Default is Text.
69
77
/// </summary>
70
- public SyntaxWriterType SyntaxWriterType { get ; set ; }
78
+ public string SyntaxWriterType
79
+ {
80
+ get => _syntaxWriterType . ToString ( ) ;
81
+ set => _syntaxWriterType = string . IsNullOrWhiteSpace ( value ) ? default : ( SyntaxWriterType ) Enum . Parse ( typeof ( SyntaxWriterType ) , value , true ) ;
82
+ }
71
83
72
84
/// <summary>
73
85
/// Only include API of the specified kinds. Legal values: A, Assembly, Namespace, N, T, Type, Field, F, P, Property, Method, M, Event, E, All. Default is All.
74
86
/// </summary>
75
- public DocIdKinds DocIdKinds { get ; set ; }
87
+ public string DocIdKinds
88
+ {
89
+ get => _docIdKinds . ToString ( ) ;
90
+ set => _docIdKinds = string . IsNullOrWhiteSpace ( value ) ? Cci . Writers . DocIdKinds . All : ( DocIdKinds ) Enum . Parse ( typeof ( DocIdKinds ) , value , true ) ;
91
+ }
76
92
77
93
/// <summary>
78
94
/// Method bodies should throw PlatformNotSupportedException.
@@ -168,15 +184,15 @@ public override bool Execute()
168
184
return false ;
169
185
}
170
186
171
- string headerText = GetHeaderText ( HeaderFile , WriterType , SyntaxWriterType ) ;
187
+ string headerText = GetHeaderText ( HeaderFile , _writerType , _syntaxWriterType ) ;
172
188
bool loopPerAssembly = Directory . Exists ( OutputPath ) ;
173
189
174
190
if ( loopPerAssembly )
175
191
{
176
192
foreach ( IAssembly assembly in assemblies )
177
193
{
178
- using ( TextWriter output = GetOutput ( GetFilename ( assembly , WriterType , SyntaxWriterType ) ) )
179
- using ( IStyleSyntaxWriter syntaxWriter = GetSyntaxWriter ( output , WriterType , SyntaxWriterType ) )
194
+ using ( TextWriter output = GetOutput ( OutputPath , GetFilename ( assembly , _writerType , _syntaxWriterType ) ) )
195
+ using ( IStyleSyntaxWriter syntaxWriter = GetSyntaxWriter ( output , _writerType , _syntaxWriterType ) )
180
196
{
181
197
ICciWriter writer = null ;
182
198
try
@@ -204,7 +220,7 @@ public override bool Execute()
204
220
else
205
221
{
206
222
using ( TextWriter output = GetOutput ( OutputPath ) )
207
- using ( IStyleSyntaxWriter syntaxWriter = GetSyntaxWriter ( output , WriterType , SyntaxWriterType ) )
223
+ using ( IStyleSyntaxWriter syntaxWriter = GetSyntaxWriter ( output , _writerType , _syntaxWriterType ) )
208
224
{
209
225
ICciWriter writer = null ;
210
226
try
@@ -241,8 +257,8 @@ private static string GetHeaderText(string headerFile, WriterType writerType, Sy
241
257
242
258
string defaultHeader = string . Empty ;
243
259
// This header is for CS source only
244
- if ( ( writerType == WriterType . CSDecl || writerType == WriterType . TypeForwards ) &&
245
- syntaxWriterType == SyntaxWriterType . Text )
260
+ if ( ( writerType == GenAPI . WriterType . CSDecl || writerType == GenAPI . WriterType . TypeForwards ) &&
261
+ syntaxWriterType == GenAPI . SyntaxWriterType . Text )
246
262
{
247
263
// Write default header (culture-invariant, so that the generated file will not be language-dependent)
248
264
defaultHeader = string . Format ( CultureInfo . InvariantCulture ,
@@ -271,11 +287,11 @@ private static string GetFilename(IAssembly assembly, WriterType writer, SyntaxW
271
287
string name = assembly . Name . Value ;
272
288
return writer switch
273
289
{
274
- WriterType . DocIds or WriterType . TypeForwards => name + ".txt" ,
290
+ GenAPI . WriterType . DocIds or GenAPI . WriterType . TypeForwards => name + ".txt" ,
275
291
_ => syntax switch
276
292
{
277
- SyntaxWriterType . Xml => name + ".xml" ,
278
- SyntaxWriterType . Html => name + ".html" ,
293
+ GenAPI . SyntaxWriterType . Xml => name + ".xml" ,
294
+ GenAPI . SyntaxWriterType . Html => name + ".html" ,
279
295
_ => name + ".cs" ,
280
296
} ,
281
297
} ;
@@ -330,13 +346,13 @@ private static ICciFilter GetFilter(
330
346
331
347
private static IStyleSyntaxWriter GetSyntaxWriter ( TextWriter output , WriterType writer , SyntaxWriterType syntax )
332
348
{
333
- if ( writer != WriterType . CSDecl && writer != WriterType . TypeList )
349
+ if ( writer != GenAPI . WriterType . CSDecl && writer != GenAPI . WriterType . TypeList )
334
350
return null ;
335
351
336
352
return syntax switch
337
353
{
338
- SyntaxWriterType . Xml => new OpenXmlSyntaxWriter ( output ) ,
339
- SyntaxWriterType . Html => new HtmlSyntaxWriter ( output ) ,
354
+ GenAPI . SyntaxWriterType . Xml => new OpenXmlSyntaxWriter ( output ) ,
355
+ GenAPI . SyntaxWriterType . Html => new HtmlSyntaxWriter ( output ) ,
340
356
_ => new TextSyntaxWriter ( output ) { SpacesInIndent = 4 } ,
341
357
} ;
342
358
}
@@ -354,18 +370,18 @@ private ICciWriter GetWriter(TextWriter output, ISyntaxWriter syntaxWriter, bool
354
370
ExcludeAttributesList ,
355
371
FollowTypeForwards ) ;
356
372
357
- switch ( WriterType )
373
+ switch ( _writerType )
358
374
{
359
- case WriterType . DocIds :
360
- return new DocumentIdWriter ( output , filter , DocIdKinds ) ;
361
- case WriterType . TypeForwards :
375
+ case GenAPI . WriterType . DocIds :
376
+ return new DocumentIdWriter ( output , filter , _docIdKinds ) ;
377
+ case GenAPI . WriterType . TypeForwards :
362
378
return new TypeForwardWriter ( output , filter )
363
379
{
364
380
IncludeForwardedTypes = true
365
381
} ;
366
- case WriterType . TypeList :
382
+ case GenAPI . WriterType . TypeList :
367
383
return new TypeListWriter ( syntaxWriter , filter ) ;
368
- case WriterType . CSDecl :
384
+ case GenAPI . WriterType . CSDecl :
369
385
default :
370
386
{
371
387
CSharpWriter writer = new ( syntaxWriter , filter , ApiOnly ) ;
0 commit comments