Skip to content

Commit

Permalink
Allow authoring scenarios to make use of abstract classes in their im…
Browse files Browse the repository at this point in the history
…plementation (#1512)

* Allow abstract class as base class for authored types by making them an implementation detail that is not projected given abstract classes aren't projected in WinRT

* Add test case

* Move setting of CsWinRTWindowsMetadata to the property group not within a target so that the WinRT component source generator can also pick it up
  • Loading branch information
manodasanW authored Feb 22, 2024
1 parent b5c4eb9 commit 0b6f872
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions nuget/Microsoft.Windows.CsWinRT.targets
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<CsWinRTExeTFM Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) == 7">net7.0</CsWinRTExeTFM>
<CsWinRTExeTFM Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) >= 8">net8.0</CsWinRTExeTFM>
<CsWinRTExeTFM Condition="'$(CsWinRTExeTFM)' == ''">netstandard2.0</CsWinRTExeTFM>
<CsWinRTWindowsMetadata Condition="'$(CsWinRTWindowsMetadata)' == ''">$(WindowsSDKVersion.TrimEnd('\'))</CsWinRTWindowsMetadata>
<CsWinRTWindowsMetadata Condition="'$(CsWinRTWindowsMetadata)' == ''">$(TargetPlatformVersion)</CsWinRTWindowsMetadata>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -114,8 +116,6 @@ Copyright (C) Microsoft Corporation. All rights reserved.
-->
<CsWinRTCommand>"$(CsWinRTExe)" %40"$(CsWinRTResponseFile)"</CsWinRTCommand>
<CsWinRTCommandPrivateProjection>"$(CsWinRTExe)" %40"$(CsWinRTResponseFilePrivateProjection)"</CsWinRTCommandPrivateProjection>
<CsWinRTWindowsMetadata Condition="'$(CsWinRTWindowsMetadata)' == ''">$(WindowsSDKVersion.TrimEnd('\'))</CsWinRTWindowsMetadata>
<CsWinRTWindowsMetadata Condition="'$(CsWinRTWindowsMetadata)' == ''">$(TargetPlatformVersion)</CsWinRTWindowsMetadata>
<CsWinRTWindowsMetadataInput Condition="'$(CsWinRTWindowsMetadata)' != ''">-input $(CsWinRTWindowsMetadata)</CsWinRTWindowsMetadataInput>
</PropertyGroup>

Expand Down
4 changes: 3 additions & 1 deletion src/Authoring/WinRT.SourceGenerator/WinRTTypeWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2016,7 +2016,9 @@ void AddComponentType(INamedTypeSymbol type, Action visitTypeDeclaration = null)
TypeAttributes.BeforeFieldInit;

// extends
if (type.BaseType != null)
// WinRT doesn't support projecting abstract classes.
// If the base class is one, ignore it.
if (type.BaseType != null && !type.BaseType.IsAbstract)
{
baseType = GetTypeReference(type.BaseType);
}
Expand Down
4 changes: 4 additions & 0 deletions src/Tests/AuthoringTest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1474,6 +1474,10 @@ bool IDictionary<string, int>.TryGetValue(string key, out int value)
}
}

public sealed class TestCollection : CollectionBase
{
}

public partial interface IPartialInterface
{
public string GetNumberAsString();
Expand Down

0 comments on commit 0b6f872

Please sign in to comment.