@@ -363,7 +363,7 @@ FunctionPointerParameterSyntax ToFunctionPointerParameter(ParameterSyntax p)
363363
364364 // We can declare this method as a property accessor if it represents a property.
365365 // We must also confirm that the property type is the same in both cases, because sometimes they aren't (e.g. IUIAutomationProxyFactoryEntry.ClassName).
366- if ( methodDefinition . Generator . TryGetPropertyAccessorInfo ( methodDefinition , originalIfaceName , context , out IdentifierNameSyntax ? propertyName , out SyntaxKind ? accessorKind , out TypeSyntax ? propertyType ) &&
366+ if ( methodDefinition . Generator . TryGetPropertyAccessorInfo ( methodDefinition , originalIfaceName , context , out IdentifierNameSyntax ? propertyName , out SyntaxKind ? accessorKind , out TypeSyntax ? propertyType , out MarshalAsAttribute ? propertyMarshalAsAttribute ) &&
367367 declaredProperties . Contains ( propertyName . Identifier . ValueText ) )
368368 {
369369 if ( emulateMemberFunctionCallConv )
@@ -541,7 +541,7 @@ StatementSyntax InvokeVtblAndThrow() => ExpressionStatement(InvocationExpression
541541
542542 if ( ccwThisParameter is not null && ! ccwMethodsToSkip . Contains ( methodDefHandle ) )
543543 {
544- if ( this . TryGetPropertyAccessorInfo ( methodDefinition , originalIfaceName , context , out propertyName , out accessorKind , out propertyType ) &&
544+ if ( this . TryGetPropertyAccessorInfo ( methodDefinition , originalIfaceName , context , out propertyName , out accessorKind , out propertyType , out propertyMarshalAsAttribute ) &&
545545 ifaceDeclaredProperties ! . Contains ( propertyName . Identifier . ValueText ) )
546546 {
547547 switch ( accessorKind )
@@ -889,11 +889,25 @@ static ExpressionSyntax ThisPointer(PointerTypeSyntax? typedPointer = null)
889889 // Adding an accessor to a property later than the very next row would screw up the virtual method table ordering.
890890 // We must also confirm that the property type is the same in both cases, because sometimes they aren't (e.g. IUIAutomationProxyFactoryEntry.ClassName).
891891 // Don't do this if we are using GeneratedComInterface because that doesn't support properties yet. https://github.com/dotnet/runtime/issues/96502
892- if ( methodDefinition . Generator . TryGetPropertyAccessorInfo ( methodDefinition , actualIfaceName , context , out IdentifierNameSyntax ? propertyName , out SyntaxKind ? accessorKind , out TypeSyntax ? propertyType ) &&
892+ if ( methodDefinition . Generator . TryGetPropertyAccessorInfo ( methodDefinition , actualIfaceName , context , out IdentifierNameSyntax ? propertyName , out SyntaxKind ? accessorKind , out TypeSyntax ? propertyType , out MarshalAsAttribute ? propertyMarshalAsAttribute ) &&
893893 declaredProperties . Contains ( propertyName . Identifier . ValueText ) )
894894 {
895895 AccessorDeclarationSyntax accessor = AccessorDeclaration ( accessorKind . Value ) . WithSemicolonToken ( Semicolon ) ;
896896
897+ if ( propertyMarshalAsAttribute is not null )
898+ {
899+ if ( accessorKind == SyntaxKind . GetAccessorDeclaration )
900+ {
901+ accessor = accessor . AddAttributeLists (
902+ AttributeList ( ) . WithTarget ( AttributeTargetSpecifier ( Token ( SyntaxKind . ReturnKeyword ) ) ) . AddAttributes ( MarshalAs ( propertyMarshalAsAttribute , null ) ) ) ;
903+ }
904+ else
905+ {
906+ accessor = accessor . AddAttributeLists (
907+ AttributeList ( ) . WithTarget ( AttributeTargetSpecifier ( Token ( SyntaxKind . ParamKeyword ) ) ) . AddAttributes ( MarshalAs ( propertyMarshalAsAttribute , null ) ) ) ;
908+ }
909+ }
910+
897911 if ( members . Count > 0 && members [ members . Count - 1 ] is PropertyDeclarationSyntax lastProperty && lastProperty . Identifier . ValueText == propertyName . Identifier . ValueText )
898912 {
899913 // Add the accessor to the existing property declaration.
@@ -1240,7 +1254,7 @@ private ISet<string> GetDeclarableProperties(IEnumerable<QualifiedMethodDefiniti
12401254 foreach ( QualifiedMethodDefinition methodDefinition in methods )
12411255 {
12421256 rowIndex ++ ;
1243- if ( methodDefinition . Generator . TryGetPropertyAccessorInfo ( methodDefinition , ifaceName , context , out IdentifierNameSyntax ? propertyName , out SyntaxKind ? accessorKind , out TypeSyntax ? propertyType ) )
1257+ if ( methodDefinition . Generator . TryGetPropertyAccessorInfo ( methodDefinition , ifaceName , context , out IdentifierNameSyntax ? propertyName , out SyntaxKind ? accessorKind , out TypeSyntax ? propertyType , out MarshalAsAttribute ? propertyMarshalAsAttribute ) )
12441258 {
12451259 if ( badProperties . Contains ( propertyName . Identifier . ValueText ) )
12461260 {
@@ -1276,11 +1290,19 @@ void ReportBadProperty()
12761290 return goodProperties . Count == 0 ? ImmutableHashSet < string > . Empty : new HashSet < string > ( goodProperties . Keys , StringComparer . Ordinal ) ;
12771291 }
12781292
1279- private bool TryGetPropertyAccessorInfo ( QualifiedMethodDefinition qmd , string ifaceName , Context context , [ NotNullWhen ( true ) ] out IdentifierNameSyntax ? propertyName , [ NotNullWhen ( true ) ] out SyntaxKind ? accessorKind , [ NotNullWhen ( true ) ] out TypeSyntax ? propertyType )
1293+ private bool TryGetPropertyAccessorInfo (
1294+ QualifiedMethodDefinition qmd ,
1295+ string ifaceName ,
1296+ Context context ,
1297+ [ NotNullWhen ( true ) ] out IdentifierNameSyntax ? propertyName ,
1298+ [ NotNullWhen ( true ) ] out SyntaxKind ? accessorKind ,
1299+ [ NotNullWhen ( true ) ] out TypeSyntax ? propertyType ,
1300+ out MarshalAsAttribute ? marshalAsAttribute )
12801301 {
12811302 propertyName = null ;
12821303 accessorKind = null ;
12831304 propertyType = null ;
1305+ marshalAsAttribute = null ;
12841306
12851307 if ( ! this . canDeclareProperties )
12861308 {
@@ -1333,7 +1355,9 @@ private bool TryGetPropertyAccessorInfo(QualifiedMethodDefinition qmd, string if
13331355
13341356 Parameter propertyTypeParameter = qmd . Reader . GetParameter ( parameters . Skip ( 1 ) . Single ( ) ) ;
13351357 TypeHandleInfo propertyTypeInfo = signature . ParameterTypes [ 0 ] ;
1336- propertyType = propertyTypeInfo . ToTypeSyntax ( syntaxSettings , GeneratingElement . Property , propertyTypeParameter . GetCustomAttributes ( ) . QualifyWith ( qmd . Generator ) , propertyTypeParameter . Attributes ) . Type ;
1358+ TypeSyntaxAndMarshaling propertyTypeSyntax = propertyTypeInfo . ToTypeSyntax ( syntaxSettings , GeneratingElement . Property , propertyTypeParameter . GetCustomAttributes ( ) . QualifyWith ( qmd . Generator ) , propertyTypeParameter . Attributes ) ;
1359+ marshalAsAttribute = propertyTypeSyntax . MarshalAsAttribute ;
1360+ propertyType = propertyTypeSyntax . Type ;
13371361
13381362 if ( isGetter )
13391363 {
0 commit comments