@@ -196,20 +196,22 @@ private static void CreateSampleRegistry(SourceProductionContext ctx, Dictionary
196196 ctx . AddSource ( "ToolkitSampleRegistry.g.cs" , source ) ;
197197 }
198198
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 )
203204 {
204205 ReportDiagnosticsForInvalidAttributeUsage ( ctx , toolkitSampleAttributeData , optionsPaneAttribute , generatedOptionPropertyData ) ;
205206 ReportDiagnosticsForLinkedOptionsPane ( ctx , toolkitSampleAttributeData , optionsPaneAttribute ) ;
206207 ReportDiagnosticsGeneratedOptionsPane ( ctx , toolkitSampleAttributeData , generatedOptionPropertyData ) ;
207208 }
208209
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 )
213215 {
214216 var toolkitAttributesOnUnsupportedType = toolkitSampleAttributeData . Where ( x => x . Symbol is INamedTypeSymbol namedSym && ! IsValidXamlControl ( namedSym ) ) ;
215217 var optionsAttributeOnUnsupportedType = optionsPaneAttribute . Where ( x => x . Item2 is INamedTypeSymbol namedSym && ! IsValidXamlControl ( namedSym ) ) ;
@@ -229,8 +231,9 @@ private static void ReportDiagnosticsForInvalidAttributeUsage(SourceProductionCo
229231
230232 }
231233
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 )
234237 {
235238 foreach ( var sampleIdGroup in toolkitSampleAttributeData . GroupBy ( x => x . Attribute . Id ) )
236239 {
@@ -239,20 +242,23 @@ private static void ReportDiagnosticsForConflictingSampleId(SourceProductionCont
239242 }
240243 }
241244
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 )
245249 {
246250 // 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 ) ) ;
248253
249254 foreach ( var item in optionsPaneAttributeWithMissingOrInvalidSampleId )
250255 ctx . ReportDiagnostic ( Diagnostic . Create ( DiagnosticDescriptors . OptionsPaneAttributeWithMissingOrInvalidSampleId , item . Item2 . Locations . FirstOrDefault ( ) ) ) ;
251256 }
252257
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 )
256262 {
257263 ReportGeneratedMultiChoiceOptionsPaneDiagnostics ( ctx , generatedOptionPropertyData ) ;
258264
@@ -263,18 +269,20 @@ private static void ReportDiagnosticsGeneratedOptionsPane(SourceProductionContex
263269 ctx . ReportDiagnostic ( Diagnostic . Create ( DiagnosticDescriptors . SamplePaneOptionAttributeOnNonSample , item . Item1 . Locations . FirstOrDefault ( ) ) ) ;
264270
265271 // 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
270277
271278 foreach ( var item in generatedOptionsWithBadName )
272279 ctx . ReportDiagnostic ( Diagnostic . Create ( DiagnosticDescriptors . SamplePaneOptionWithBadName , item . Item1 . Locations . FirstOrDefault ( ) , item . Item1 . ToString ( ) ) ) ;
273280
274281 // 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.
278286
279287 foreach ( var item in generatedOptionsWithDuplicateName )
280288 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
332340 yield return item switch
333341 {
334342 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 } "")",
336344 ToolkitSampleBoolOptionAttribute boolAttribute =>
337345 $@ "new { typeof ( ToolkitSampleBoolOptionMetadataViewModel ) . FullName } (name: ""{ boolAttribute . Name } "", defaultState: { boolAttribute . DefaultState ? . ToString ( ) . ToLower ( ) } , title: ""{ boolAttribute . Title } "")",
338346 ToolkitSampleNumericOptionAttribute numericAttribute =>
0 commit comments