@@ -32,7 +32,6 @@ internal abstract class DocsAPI : IDocsAPI
32
32
Params . Any ( p => p . Value . IsDocsEmpty ( ) ) ||
33
33
TypeParams . Any ( tp => tp . Value . IsDocsEmpty ( ) ) ;
34
34
35
- public abstract bool Changed { get ; set ; }
36
35
public string FilePath { get ; set ; } = string . Empty ;
37
36
38
37
public string DocId => _docId ??= GetApiSignatureDocId ( ) ;
@@ -49,14 +48,7 @@ public List<DocsParameter> Parameters
49
48
if ( _parameters == null )
50
49
{
51
50
XElement ? xeParameters = XERoot . Element ( "Parameters" ) ;
52
- if ( xeParameters == null )
53
- {
54
- _parameters = new ( ) ;
55
- }
56
- else
57
- {
58
- _parameters = xeParameters . Elements ( "Parameter" ) . Select ( x => new DocsParameter ( x ) ) . ToList ( ) ;
59
- }
51
+ _parameters = xeParameters == null ? ( List < DocsParameter > ) new ( ) : xeParameters . Elements ( "Parameter" ) . Select ( x => new DocsParameter ( x ) ) . ToList ( ) ;
60
52
}
61
53
return _parameters ;
62
54
}
@@ -72,222 +64,59 @@ public List<DocsTypeParameter> TypeParameters
72
64
if ( _typeParameters == null )
73
65
{
74
66
XElement ? xeTypeParameters = XERoot . Element ( "TypeParameters" ) ;
75
- if ( xeTypeParameters == null )
76
- {
77
- _typeParameters = new ( ) ;
78
- }
79
- else
80
- {
81
- _typeParameters = xeTypeParameters . Elements ( "TypeParameter" ) . Select ( x => new DocsTypeParameter ( x ) ) . ToList ( ) ;
82
- }
67
+ _typeParameters = xeTypeParameters == null ? ( List < DocsTypeParameter > ) new ( ) : xeTypeParameters . Elements ( "TypeParameter" ) . Select ( x => new DocsTypeParameter ( x ) ) . ToList ( ) ;
83
68
}
84
69
return _typeParameters ;
85
70
}
86
71
}
87
72
88
- public XElement Docs
89
- {
90
- get
91
- {
92
- return XERoot . Element ( "Docs" ) ?? throw new NullReferenceException ( $ "Docs section was null in { FilePath } ") ;
93
- }
94
- }
73
+ public XElement Docs => XERoot . Element ( "Docs" ) ?? throw new NullReferenceException ( $ "Docs section was null in { FilePath } ") ;
95
74
96
75
/// <summary>
97
76
/// The param elements found inside the Docs section.
98
77
/// </summary>
99
- public List < DocsParam > Params
100
- {
101
- get
102
- {
103
- if ( _params == null )
104
- {
105
- if ( Docs != null )
106
- {
107
- _params = Docs . Elements ( "param" ) . Select ( x => new DocsParam ( this , x ) ) . ToList ( ) ;
108
- }
109
- else
110
- {
111
- _params = new List < DocsParam > ( ) ;
112
- }
113
- }
114
- return _params ;
115
- }
116
- }
78
+ public List < DocsParam > Params => _params ??= Docs != null ? Docs . Elements ( "param" ) . Select ( x => new DocsParam ( this , x ) ) . ToList ( ) : new List < DocsParam > ( ) ;
117
79
118
80
/// <summary>
119
81
/// The typeparam elements found inside the Docs section.
120
82
/// </summary>
121
- public List < DocsTypeParam > TypeParams
122
- {
123
- get
124
- {
125
- if ( _typeParams == null )
126
- {
127
- if ( Docs != null )
128
- {
129
- _typeParams = Docs . Elements ( "typeparam" ) . Select ( x => new DocsTypeParam ( this , x ) ) . ToList ( ) ;
130
- }
131
- else
132
- {
133
- _typeParams = new ( ) ;
134
- }
135
- }
136
- return _typeParams ;
137
- }
138
- }
83
+ public List < DocsTypeParam > TypeParams => _typeParams ??= Docs != null ? Docs . Elements ( "typeparam" ) . Select ( x => new DocsTypeParam ( this , x ) ) . ToList ( ) : ( List < DocsTypeParam > ) new ( ) ;
139
84
140
- public List < string > SeeAlsoCrefs
141
- {
142
- get
143
- {
144
- if ( _seeAlsoCrefs == null )
145
- {
146
- if ( Docs != null )
147
- {
148
- _seeAlsoCrefs = Docs . Elements ( "seealso" ) . Select ( x => XmlHelper . GetAttributeValue ( x , "cref" ) . DocIdEscaped ( ) ) . ToList ( ) ;
149
- }
150
- else
151
- {
152
- _seeAlsoCrefs = new ( ) ;
153
- }
154
- }
155
- return _seeAlsoCrefs ;
156
- }
157
- }
85
+ public List < string > SeeAlsoCrefs => _seeAlsoCrefs ??= Docs != null ? Docs . Elements ( "seealso" ) . Select ( x => XmlHelper . GetAttributeValue ( x , "cref" ) . DocIdEscaped ( ) ) . ToList ( ) : ( List < string > ) new ( ) ;
158
86
159
- public List < string > AltMembers
160
- {
161
- get
162
- {
163
- if ( _altMemberCrefs == null )
164
- {
165
- if ( Docs != null )
166
- {
167
- _altMemberCrefs = Docs . Elements ( "altmember" ) . Select ( x => XmlHelper . GetAttributeValue ( x , "cref" ) . DocIdEscaped ( ) ) . ToList ( ) ;
168
- }
169
- else
170
- {
171
- _altMemberCrefs = new ( ) ;
172
- }
173
- }
174
- return _altMemberCrefs ;
175
- }
176
- }
87
+ public List < string > AltMembers => _altMemberCrefs ??= Docs != null ? Docs . Elements ( "altmember" ) . Select ( x => XmlHelper . GetAttributeValue ( x , "cref" ) . DocIdEscaped ( ) ) . ToList ( ) : ( List < string > ) new ( ) ;
177
88
178
- public List < DocsRelated > Relateds
179
- {
180
- get
181
- {
182
- if ( _relateds == null )
183
- {
184
- if ( Docs != null )
185
- {
186
- _relateds = Docs . Elements ( "related" ) . Select ( x => new DocsRelated ( this , x ) ) . ToList ( ) ;
187
- }
188
- else
189
- {
190
- _relateds = new ( ) ;
191
- }
192
- }
193
- return _relateds ;
194
- }
195
- }
89
+ public List < DocsRelated > Relateds => _relateds ??= Docs != null ? Docs . Elements ( "related" ) . Select ( x => new DocsRelated ( this , x ) ) . ToList ( ) : ( List < DocsRelated > ) new ( ) ;
90
+
91
+ public abstract string Summary { get ; }
92
+
93
+ public abstract string Value { get ; }
196
94
197
- public abstract string Summary { get ; set ; }
198
- public abstract string Value { get ; set ; }
199
95
public abstract string ReturnType { get ; }
200
- public abstract string Returns { get ; set ; }
201
- public abstract string Remarks { get ; set ; }
202
96
203
- public abstract List < DocsException > Exceptions { get ; }
97
+ public abstract string Returns { get ; }
204
98
205
- public List < DocsAssemblyInfo > AssemblyInfos
206
- {
207
- get
208
- {
209
- if ( _assemblyInfos == null )
210
- {
211
- _assemblyInfos = new List < DocsAssemblyInfo > ( ) ;
212
- }
213
- return _assemblyInfos ;
214
- }
215
- }
99
+ public abstract string Remarks { get ; }
216
100
217
- public DocsParam SaveParam ( XElement xeIntelliSenseXmlParam )
218
- {
219
- XElement xeDocsParam = new XElement ( xeIntelliSenseXmlParam . Name ) ;
220
- xeDocsParam . ReplaceAttributes ( xeIntelliSenseXmlParam . Attributes ( ) ) ;
221
- XmlHelper . SaveFormattedAsXml ( xeDocsParam , xeIntelliSenseXmlParam . Value ) ;
222
- DocsParam docsParam = new DocsParam ( this , xeDocsParam ) ;
223
- Changed = true ;
224
- return docsParam ;
225
- }
101
+ public abstract List < DocsException > Exceptions { get ; }
226
102
227
- public APIKind Kind
228
- {
229
- get
230
- {
231
- return this switch
232
- {
233
- DocsMember _ => APIKind . Member ,
234
- DocsType _ => APIKind . Type ,
235
- _ => throw new ArgumentException ( "Unrecognized IDocsAPI object" )
236
- } ;
237
- }
238
- }
103
+ public List < DocsAssemblyInfo > AssemblyInfos => _assemblyInfos ??= new List < DocsAssemblyInfo > ( ) ;
239
104
240
- public DocsTypeParam AddTypeParam ( string name , string value )
105
+ public APIKind Kind => this switch
241
106
{
242
- XElement typeParam = new XElement ( "typeparam" ) ;
243
- typeParam . SetAttributeValue ( "name" , name ) ;
244
- XmlHelper . AddChildFormattedAsXml ( Docs , typeParam , value ) ;
245
- Changed = true ;
246
- return new DocsTypeParam ( this , typeParam ) ;
247
- }
107
+ DocsMember _ => APIKind . Member ,
108
+ DocsType _ => APIKind . Type ,
109
+ _ => throw new ArgumentException ( "Unrecognized IDocsAPI object" )
110
+ } ;
248
111
249
112
// For Types, these elements are called TypeSignature.
250
113
// For Members, these elements are called MemberSignature.
251
114
protected abstract string GetApiSignatureDocId ( ) ;
252
115
253
- protected string GetNodesInPlainText ( string name )
254
- {
255
- if ( TryGetElement ( name , addIfMissing : false , out XElement ? element ) )
256
- {
257
- if ( name == "remarks" )
258
- {
259
- XElement ? formatElement = element . Element ( "format" ) ;
260
- if ( formatElement != null )
261
- {
262
- element = formatElement ;
263
- }
264
- }
265
-
266
- return XmlHelper . GetNodesInPlainText ( element ) ;
267
- }
268
- return string . Empty ;
269
- }
270
-
271
- protected void SaveFormattedAsXml ( string name , string value , bool addIfMissing )
272
- {
273
- if ( TryGetElement ( name , addIfMissing , out XElement ? element ) )
274
- {
275
- XmlHelper . SaveFormattedAsXml ( element , value ) ;
276
- Changed = true ;
277
- }
278
- }
279
-
280
- protected void SaveFormattedAsMarkdown ( string name , string value , bool addIfMissing , bool isMember )
281
- {
282
- if ( TryGetElement ( name , addIfMissing , out XElement ? element ) )
283
- {
284
- XmlHelper . SaveFormattedAsMarkdown ( element , value , isMember ) ;
285
- Changed = true ;
286
- }
287
- }
116
+ protected string GetNodesInPlainText ( string name ) => TryGetElement ( name , out XElement ? element ) ? XmlHelper . GetNodesInPlainText ( name , element ) : string . Empty ;
288
117
289
118
// Returns true if the element existed or had to be created with "To be added." as value. Returns false the element was not found and a new one was not created.
290
- private bool TryGetElement ( string name , bool addIfMissing , [ NotNullWhen ( returnValue : true ) ] out XElement ? element )
119
+ private bool TryGetElement ( string name , [ NotNullWhen ( returnValue : true ) ] out XElement ? element )
291
120
{
292
121
element = null ;
293
122
@@ -298,12 +127,6 @@ private bool TryGetElement(string name, bool addIfMissing, [NotNullWhen(returnVa
298
127
299
128
element = Docs . Element ( name ) ;
300
129
301
- if ( element == null && addIfMissing )
302
- {
303
- element = new XElement ( name ) ;
304
- XmlHelper . AddChildFormattedAsXml ( Docs , element , Configuration . ToBeAdded ) ;
305
- }
306
-
307
130
return element != null ;
308
131
}
309
132
}
0 commit comments