Skip to content

Commit

Permalink
Propagate the 'this' keyword in LibraryImports (#102793)
Browse files Browse the repository at this point in the history
Since Roslyn just lowers the extension methods to a call to the static method there's no reason we shouldn't support creating extension methods that are also LibraryImport methods. This adds the IsExplicitThis property to TypePositionInfo and copies this to the generated signature if it is true.
  • Loading branch information
jtschuster committed May 30, 2024
1 parent 3393b4d commit 36a85b0
Show file tree
Hide file tree
Showing 6 changed files with 325 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,11 @@ public static SyntaxTokenList GetManagedParameterModifiers(TypePositionInfo type
}
}

if (typeInfo.IsExplicitThis)
{
tokens = tokens.Add(Token(SyntaxKind.ThisKeyword));
}

return tokens;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

using System;
using System.Collections.Generic;

using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;

namespace Microsoft.Interop
Expand Down Expand Up @@ -77,6 +78,7 @@ public static int IncrementIndex(int index)

public int ManagedIndex { get; init; } = UnsetIndex;
public int NativeIndex { get; init; } = UnsetIndex;
public bool IsExplicitThis { get; init; }

public static TypePositionInfo CreateForParameter(IParameterSymbol paramSymbol, MarshallingInfo marshallingInfo, Compilation compilation)
{
Expand All @@ -88,7 +90,8 @@ public static TypePositionInfo CreateForParameter(IParameterSymbol paramSymbol,
RefKind = paramSymbol.RefKind,
ByValueContentsMarshalKind = byValueContentsMarshalKind,
ByValueMarshalAttributeLocations = (inLocation, outLocation),
ScopedKind = paramSymbol.ScopedKind
ScopedKind = paramSymbol.ScopedKind,
IsExplicitThis = ((ParameterSyntax)paramSymbol.DeclaringSyntaxReferences[0].GetSyntax()).Modifiers.Any(SyntaxKind.ThisKeyword)
};

return typeInfo;
Expand Down
Loading

0 comments on commit 36a85b0

Please sign in to comment.