@@ -14,6 +14,9 @@ namespace Bunit.Web.Stubs;
1414[ Generator ]
1515public class StubGenerator : IIncrementalGenerator
1616{
17+ private static string CascadingParameterAttributeQualifier ;
18+ private const string ParameterAttributeQualifier = "Microsoft.AspNetCore.Components.ParameterAttribute" ;
19+
1720 /// <inheritdoc/>
1821 public void Initialize ( IncrementalGeneratorInitializationContext context )
1922 {
@@ -131,15 +134,16 @@ private static bool GenerateStubComponent(StubClassInfo classInfo, SourceProduct
131134 sourceBuilder . AppendLine ( $ "internal partial class { classInfo . StubClassName } : Microsoft.AspNetCore.Components.ComponentBase") ;
132135 sourceBuilder . Append ( "{" ) ;
133136
137+ CascadingParameterAttributeQualifier = "Microsoft.AspNetCore.Components.CascadingParameterAttribute" ;
134138 foreach ( var member in targetTypeSymbol
135139 . GetMembers ( )
136140 . OfType < IPropertySymbol > ( )
137141 . Where ( p => p . GetAttributes ( )
138142 . Any ( attr =>
139143 attr . AttributeClass ? . ToDisplayString ( ) ==
140- "Microsoft.AspNetCore.Components.ParameterAttribute" ||
144+ ParameterAttributeQualifier ||
141145 attr . AttributeClass ? . ToDisplayString ( ) ==
142- "Microsoft.AspNetCore.Components.CascadingParameterAttribute" ) ) )
146+ CascadingParameterAttributeQualifier ) ) )
143147 {
144148 sourceBuilder . AppendLine ( ) ;
145149
@@ -165,13 +169,13 @@ private static bool GenerateStubComponent(StubClassInfo classInfo, SourceProduct
165169 string GetAttributeLine ( ISymbol member )
166170 {
167171 var attribute = member . GetAttributes ( ) . First ( attr =>
168- attr . AttributeClass ? . ToDisplayString ( ) == "Microsoft.AspNetCore.Components.ParameterAttribute" ||
169- attr . AttributeClass ? . ToDisplayString ( ) == "Microsoft.AspNetCore.Components.CascadingParameterAttribute" ) ;
172+ attr . AttributeClass ? . ToDisplayString ( ) == ParameterAttributeQualifier ||
173+ attr . AttributeClass ? . ToDisplayString ( ) == CascadingParameterAttributeQualifier ) ;
170174
171175 var attributeLine = new StringBuilder ( "\t [" ) ;
172- if ( attribute . AttributeClass ? . ToDisplayString ( ) == "Microsoft.AspNetCore.Components.ParameterAttribute" )
176+ if ( attribute . AttributeClass ? . ToDisplayString ( ) == ParameterAttributeQualifier )
173177 {
174- attributeLine . Append ( "global::Microsoft.AspNetCore.Components.Parameter " ) ;
178+ attributeLine . Append ( $ "global::{ ParameterAttributeQualifier } ") ;
175179 var captureUnmatchedValuesArg = attribute . NamedArguments
176180 . FirstOrDefault ( arg => arg . Key == "CaptureUnmatchedValues" ) . Value ;
177181 if ( captureUnmatchedValuesArg . Value is bool captureUnmatchedValues )
@@ -180,10 +184,9 @@ string GetAttributeLine(ISymbol member)
180184 attributeLine . Append ( $ "(CaptureUnmatchedValues = { captureString } )") ;
181185 }
182186 }
183- else if ( attribute . AttributeClass ? . ToDisplayString ( ) ==
184- "Microsoft.AspNetCore.Components.CascadingParameterAttribute" )
187+ else if ( attribute . AttributeClass ? . ToDisplayString ( ) == CascadingParameterAttributeQualifier )
185188 {
186- attributeLine . Append ( "global::Microsoft.AspNetCore.Components.CascadingParameter " ) ;
189+ attributeLine . Append ( $ "global::{ CascadingParameterAttributeQualifier } ") ;
187190 var nameArg = attribute . NamedArguments . FirstOrDefault ( arg => arg . Key == "Name" ) . Value ;
188191 if ( ! nameArg . IsNull )
189192 {
0 commit comments