@@ -196,20 +196,22 @@ private static void CreateSampleRegistry(SourceProductionContext ctx, Dictionary
196
196
ctx . AddSource ( "ToolkitSampleRegistry.g.cs" , source ) ;
197
197
}
198
198
199
- private static void ReportSampleDiagnostics ( SourceProductionContext ctx ,
200
- IEnumerable < ( ToolkitSampleAttribute Attribute , string AttachedQualifiedTypeName , ISymbol Symbol ) > toolkitSampleAttributeData ,
201
- IEnumerable < ( ToolkitSampleOptionsPaneAttribute ? , ISymbol ) > optionsPaneAttribute ,
202
- IEnumerable < ( ISymbol , ToolkitSampleOptionBaseAttribute ) > generatedOptionPropertyData )
199
+ private static void ReportSampleDiagnostics (
200
+ SourceProductionContext ctx ,
201
+ IEnumerable < ( ToolkitSampleAttribute Attribute , string AttachedQualifiedTypeName , ISymbol Symbol ) > toolkitSampleAttributeData ,
202
+ IEnumerable < ( ToolkitSampleOptionsPaneAttribute ? , ISymbol ) > optionsPaneAttribute ,
203
+ IEnumerable < ( ISymbol , ToolkitSampleOptionBaseAttribute ) > generatedOptionPropertyData )
203
204
{
204
205
ReportDiagnosticsForInvalidAttributeUsage ( ctx , toolkitSampleAttributeData , optionsPaneAttribute , generatedOptionPropertyData ) ;
205
206
ReportDiagnosticsForLinkedOptionsPane ( ctx , toolkitSampleAttributeData , optionsPaneAttribute ) ;
206
207
ReportDiagnosticsGeneratedOptionsPane ( ctx , toolkitSampleAttributeData , generatedOptionPropertyData ) ;
207
208
}
208
209
209
- private static void ReportDiagnosticsForInvalidAttributeUsage ( SourceProductionContext ctx ,
210
- IEnumerable < ( ToolkitSampleAttribute Attribute , string AttachedQualifiedTypeName , ISymbol Symbol ) > toolkitSampleAttributeData ,
211
- IEnumerable < ( ToolkitSampleOptionsPaneAttribute ? , ISymbol ) > optionsPaneAttribute ,
212
- IEnumerable < ( ISymbol , ToolkitSampleOptionBaseAttribute ) > generatedOptionPropertyData )
210
+ private static void ReportDiagnosticsForInvalidAttributeUsage (
211
+ SourceProductionContext ctx ,
212
+ IEnumerable < ( ToolkitSampleAttribute Attribute , string AttachedQualifiedTypeName , ISymbol Symbol ) > toolkitSampleAttributeData ,
213
+ IEnumerable < ( ToolkitSampleOptionsPaneAttribute ? , ISymbol ) > optionsPaneAttribute ,
214
+ IEnumerable < ( ISymbol , ToolkitSampleOptionBaseAttribute ) > generatedOptionPropertyData )
213
215
{
214
216
var toolkitAttributesOnUnsupportedType = toolkitSampleAttributeData . Where ( x => x . Symbol is INamedTypeSymbol namedSym && ! IsValidXamlControl ( namedSym ) ) ;
215
217
var optionsAttributeOnUnsupportedType = optionsPaneAttribute . Where ( x => x . Item2 is INamedTypeSymbol namedSym && ! IsValidXamlControl ( namedSym ) ) ;
@@ -229,8 +231,9 @@ private static void ReportDiagnosticsForInvalidAttributeUsage(SourceProductionCo
229
231
230
232
}
231
233
232
- private static void ReportDiagnosticsForConflictingSampleId ( SourceProductionContext ctx ,
233
- IEnumerable < ( ToolkitSampleAttribute Attribute , string AttachedQualifiedTypeName , ISymbol Symbol ) > toolkitSampleAttributeData )
234
+ private static void ReportDiagnosticsForConflictingSampleId (
235
+ SourceProductionContext ctx ,
236
+ IEnumerable < ( ToolkitSampleAttribute Attribute , string AttachedQualifiedTypeName , ISymbol Symbol ) > toolkitSampleAttributeData )
234
237
{
235
238
foreach ( var sampleIdGroup in toolkitSampleAttributeData . GroupBy ( x => x . Attribute . Id ) )
236
239
{
@@ -239,20 +242,23 @@ private static void ReportDiagnosticsForConflictingSampleId(SourceProductionCont
239
242
}
240
243
}
241
244
242
- private static void ReportDiagnosticsForLinkedOptionsPane ( SourceProductionContext ctx ,
243
- IEnumerable < ( ToolkitSampleAttribute Attribute , string AttachedQualifiedTypeName , ISymbol Symbol ) > toolkitSampleAttributeData ,
244
- IEnumerable < ( ToolkitSampleOptionsPaneAttribute ? , ISymbol ) > optionsPaneAttribute )
245
+ private static void ReportDiagnosticsForLinkedOptionsPane (
246
+ SourceProductionContext ctx ,
247
+ IEnumerable < ( ToolkitSampleAttribute Attribute , string AttachedQualifiedTypeName , ISymbol Symbol ) > toolkitSampleAttributeData ,
248
+ IEnumerable < ( ToolkitSampleOptionsPaneAttribute ? , ISymbol ) > optionsPaneAttribute )
245
249
{
246
250
// Check for options pane attributes with no matching sample ID
247
- var optionsPaneAttributeWithMissingOrInvalidSampleId = optionsPaneAttribute . Where ( x => toolkitSampleAttributeData . All ( sample => sample . Attribute . Id != x . Item1 ? . SampleId ) ) ;
251
+ var optionsPaneAttributeWithMissingOrInvalidSampleId = optionsPaneAttribute . Where ( x =>
252
+ toolkitSampleAttributeData . All ( sample => sample . Attribute . Id != x . Item1 ? . SampleId ) ) ;
248
253
249
254
foreach ( var item in optionsPaneAttributeWithMissingOrInvalidSampleId )
250
255
ctx . ReportDiagnostic ( Diagnostic . Create ( DiagnosticDescriptors . OptionsPaneAttributeWithMissingOrInvalidSampleId , item . Item2 . Locations . FirstOrDefault ( ) ) ) ;
251
256
}
252
257
253
- private static void ReportDiagnosticsGeneratedOptionsPane ( SourceProductionContext ctx ,
254
- IEnumerable < ( ToolkitSampleAttribute Attribute , string AttachedQualifiedTypeName , ISymbol Symbol ) > toolkitSampleAttributeData ,
255
- IEnumerable < ( ISymbol , ToolkitSampleOptionBaseAttribute ) > generatedOptionPropertyData )
258
+ private static void ReportDiagnosticsGeneratedOptionsPane (
259
+ SourceProductionContext ctx ,
260
+ IEnumerable < ( ToolkitSampleAttribute Attribute , string AttachedQualifiedTypeName , ISymbol Symbol ) > toolkitSampleAttributeData ,
261
+ IEnumerable < ( ISymbol , ToolkitSampleOptionBaseAttribute ) > generatedOptionPropertyData )
256
262
{
257
263
ReportGeneratedMultiChoiceOptionsPaneDiagnostics ( ctx , generatedOptionPropertyData ) ;
258
264
@@ -263,18 +269,20 @@ private static void ReportDiagnosticsGeneratedOptionsPane(SourceProductionContex
263
269
ctx . ReportDiagnostic ( Diagnostic . Create ( DiagnosticDescriptors . SamplePaneOptionAttributeOnNonSample , item . Item1 . Locations . FirstOrDefault ( ) ) ) ;
264
270
265
271
// Check for generated options with an empty or invalid name.
266
- var generatedOptionsWithBadName = generatedOptionPropertyData . Where ( x => string . IsNullOrWhiteSpace ( x . Item2 . Name ) || // Must not be null or empty
267
- ! x . Item2 . Name . Any ( char . IsLetterOrDigit ) || // Must be alphanumeric
268
- x . Item2 . Name . Any ( char . IsWhiteSpace ) || // Must not have whitespace
269
- SyntaxFacts . GetKeywordKind ( x . Item2 . Name ) != SyntaxKind . None ) ; // Must not be a reserved keyword
272
+ var generatedOptionsWithBadName = generatedOptionPropertyData
273
+ . Where ( x => string . IsNullOrWhiteSpace ( x . Item2 . Name ) || // Must not be null or empty
274
+ ! x . Item2 . Name . Any ( char . IsLetterOrDigit ) || // Must be alphanumeric
275
+ x . Item2 . Name . Any ( char . IsWhiteSpace ) || // Must not have whitespace
276
+ SyntaxFacts . GetKeywordKind ( x . Item2 . Name ) != SyntaxKind . None ) ; // Must not be a reserved keyword
270
277
271
278
foreach ( var item in generatedOptionsWithBadName )
272
279
ctx . ReportDiagnostic ( Diagnostic . Create ( DiagnosticDescriptors . SamplePaneOptionWithBadName , item . Item1 . Locations . FirstOrDefault ( ) , item . Item1 . ToString ( ) ) ) ;
273
280
274
281
// Check for generated options with duplicate names.
275
- var generatedOptionsWithDuplicateName = generatedOptionPropertyData . GroupBy ( x => x . Item1 , SymbolEqualityComparer . Default ) // Group by containing symbol (allow reuse across samples)
276
- . SelectMany ( y => y . GroupBy ( x => x . Item2 . Name ) // In this symbol, group options by name.
277
- . Where ( x => x . Count ( ) > 1 ) ) ; // Options grouped by name should only contain 1 item.
282
+ var generatedOptionsWithDuplicateName = generatedOptionPropertyData
283
+ . GroupBy ( x => x . Item1 , SymbolEqualityComparer . Default ) // Group by containing symbol (allow reuse across samples)
284
+ . SelectMany ( y => y . GroupBy ( x => x . Item2 . Name ) // In this symbol, group options by name.
285
+ . Where ( x => x . Count ( ) > 1 ) ) ; // Options grouped by name should only contain 1 item.
278
286
279
287
foreach ( var item in generatedOptionsWithDuplicateName )
280
288
ctx . ReportDiagnostic ( Diagnostic . Create ( DiagnosticDescriptors . SamplePaneOptionWithDuplicateName , item . SelectMany ( x => x . Item1 . Locations ) . FirstOrDefault ( ) , item . Key ) ) ;
@@ -332,7 +340,7 @@ private static IEnumerable<string> BuildNewGeneratedSampleOptionMetadataSource(T
332
340
yield return item switch
333
341
{
334
342
ToolkitSampleMultiChoiceOptionAttribute multiChoiceAttr =>
335
- $@ "new { typeof ( ToolkitSampleMultiChoiceOptionMetadataViewModel ) . FullName } (name: ""{ multiChoiceAttr . Name } "", options: new[] {{ { string . Join ( "," , multiChoiceAttr . Choices . Select ( x => $@ "new { typeof ( MultiChoiceOption ) . FullName } (""{ x . Label } "", " "{ x . Value } "" )") . ToArray ( ) ) } }}, title: ""{ multiChoiceAttr . Title } "")",
343
+ $@ "new { typeof ( ToolkitSampleMultiChoiceOptionMetadataViewModel ) . FullName } (name: ""{ multiChoiceAttr . Name } "", options: new[] {{ { string . Join ( "," , multiChoiceAttr . Choices . Select ( x => $@ "new { typeof ( MultiChoiceOption ) . FullName } (""{ x . Label } "", { ( x . Value is string ? $ " \ "{ x . Value } \" " : x . Value ) } )") . ToArray ( ) ) } }}, title: ""{ multiChoiceAttr . Title } "")",
336
344
ToolkitSampleBoolOptionAttribute boolAttribute =>
337
345
$@ "new { typeof ( ToolkitSampleBoolOptionMetadataViewModel ) . FullName } (name: ""{ boolAttribute . Name } "", defaultState: { boolAttribute . DefaultState ? . ToString ( ) . ToLower ( ) } , title: ""{ boolAttribute . Title } "")",
338
346
ToolkitSampleNumericOptionAttribute numericAttribute =>
0 commit comments