@@ -128,7 +128,7 @@ private static bool GenerateStubComponent(StubClassInfo classInfo, SourceProduct
128128 var sourceBuilder = new StringBuilder ( ) ;
129129
130130 sourceBuilder . AppendLine ( $ "namespace { classInfo . TargetTypeNamespace } ;") ;
131- sourceBuilder . AppendLine ( $ "public partial class { classInfo . StubClassName } : Microsoft.AspNetCore.Components.ComponentBase") ;
131+ sourceBuilder . AppendLine ( $ "internal partial class { classInfo . StubClassName } : Microsoft.AspNetCore.Components.ComponentBase") ;
132132 sourceBuilder . Append ( "{" ) ;
133133
134134 foreach ( var member in targetTypeSymbol
@@ -147,13 +147,9 @@ private static bool GenerateStubComponent(StubClassInfo classInfo, SourceProduct
147147 var propertyType = member . Type . ToDisplayString ( ) ;
148148 var propertyName = member . Name ;
149149
150- var isParameterAttribute = member . GetAttributes ( ) . Any ( attr =>
151- attr . AttributeClass ? . ToDisplayString ( ) == "Microsoft.AspNetCore.Components.ParameterAttribute" ) ;
152- var attributeLine = isParameterAttribute
153- ? "\t [global::Microsoft.AspNetCore.Components.Parameter]"
154- : "\t [global::Microsoft.AspNetCore.Components.CascadingParameter]" ;
155-
150+ var attributeLine = GetAttributeLine ( member ) ;
156151 sourceBuilder . AppendLine ( attributeLine ) ;
152+
157153 sourceBuilder . AppendLine ( $ "\t public { propertyType } { propertyName } {{ get; set; }}") ;
158154 }
159155
@@ -165,6 +161,39 @@ private static bool GenerateStubComponent(StubClassInfo classInfo, SourceProduct
165161 }
166162
167163 return hasSomethingToStub ;
164+
165+ string GetAttributeLine ( IPropertySymbol member )
166+ {
167+ var attribute = member . GetAttributes ( ) . First ( attr =>
168+ attr . AttributeClass ? . ToDisplayString ( ) == "Microsoft.AspNetCore.Components.ParameterAttribute" ||
169+ attr . AttributeClass ? . ToDisplayString ( ) == "Microsoft.AspNetCore.Components.CascadingParameterAttribute" ) ;
170+
171+ var attributeLine = new StringBuilder ( "\t [" ) ;
172+ if ( attribute . AttributeClass ? . ToDisplayString ( ) == "Microsoft.AspNetCore.Components.ParameterAttribute" )
173+ {
174+ attributeLine . Append ( "global::Microsoft.AspNetCore.Components.Parameter" ) ;
175+ var captureUnmatchedValuesArg = attribute . NamedArguments
176+ . FirstOrDefault ( arg => arg . Key == "CaptureUnmatchedValues" ) . Value ;
177+ if ( captureUnmatchedValuesArg . Value is bool captureUnmatchedValues )
178+ {
179+ var captureString = captureUnmatchedValues ? "true" : "false" ;
180+ attributeLine . Append ( $ "(CaptureUnmatchedValues = { captureString } )") ;
181+ }
182+ }
183+ else if ( attribute . AttributeClass ? . ToDisplayString ( ) ==
184+ "Microsoft.AspNetCore.Components.CascadingParameterAttribute" )
185+ {
186+ attributeLine . Append ( "global::Microsoft.AspNetCore.Components.CascadingParameter" ) ;
187+ var nameArg = attribute . NamedArguments . FirstOrDefault ( arg => arg . Key == "Name" ) . Value ;
188+ if ( ! nameArg . IsNull )
189+ {
190+ attributeLine . Append ( $ "(Name = \" { nameArg . Value } \" )") ;
191+ }
192+ }
193+
194+ attributeLine . Append ( "]" ) ;
195+ return attributeLine . ToString ( ) ;
196+ }
168197 }
169198
170199 private static void GenerateInterceptorCode ( StubClassInfo stubbedComponentGroup , IEnumerable < StubClassInfo > stubClassGrouped , SourceProductionContext context )
0 commit comments