Skip to content

Commit

Permalink
Fix scenario with set only property declared across projections (#981)
Browse files Browse the repository at this point in the history
* Fix getter interface type

* Adjust for netstandard compat.

* Add test projection with a set property that references a get property from another projection.

* Add remaining test
  • Loading branch information
manodasanW authored Sep 3, 2021
1 parent a9a8631 commit 26943b2
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Projections/Test/Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

<PropertyGroup>
<CsWinRTIncludes>TestComponent;TestComponentCSharp;test_component_base;test_component_derived;</CsWinRTIncludes>
<CsWinRTExcludes>TestComponentCSharp.AnotherAssembly;</CsWinRTExcludes>
<!--PkgMicrosoft_WinUI is set in in obj\*.csproj.nuget.g.props with TargetFramework condition, doesn't support multi-targeting-->
<PkgMicrosoft_WinUI Condition="'$(PkgMicrosoft_WinUI)'==''">$([MSBuild]::NormalizeDirectory('$(NuGetPackageRoot)', 'microsoft.winui', '$(MicrosoftWinUIVersion)'))</PkgMicrosoft_WinUI>
</PropertyGroup>
Expand Down
32 changes: 32 additions & 0 deletions src/Projections/TestSubset/TestSubset.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net5.0;net6.0</TargetFrameworks>
<Platforms>x64;x86</Platforms>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Tests\TestComponentCSharp\TestComponentCSharp.vcxproj" />
<ProjectReference Include="..\..\TestWinRT\TestComponent\TestComponent.vcxproj" />
<ProjectReference Include="..\..\TestWinRT\test_component_base\test_component_base.vcxproj" />
<ProjectReference Include="..\..\TestWinRT\test_component_derived\test_component_derived.vcxproj" />
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
<ProjectReference Include="..\..\WinRT.Runtime\WinRT.Runtime.csproj" />
<ProjectReference Include="..\..\cswinrt\cswinrt.vcxproj" />
<ProjectReference Include="..\Windows\Windows.csproj" />
<ProjectReference Include="..\WinUI\WinUI.csproj" />
<ProjectReference Include="..\Test\Test.csproj" />
<InternalsVisibleTo Include="UnitTest" />
</ItemGroup>

<PropertyGroup>
<CsWinRTIncludes>TestComponentCSharp.AnotherAssembly;</CsWinRTIncludes>
<!--PkgMicrosoft_WinUI is set in in obj\*.csproj.nuget.g.props with TargetFramework condition, doesn't support multi-targeting-->
<PkgMicrosoft_WinUI Condition="'$(PkgMicrosoft_WinUI)'==''">$([MSBuild]::NormalizeDirectory('$(NuGetPackageRoot)', 'microsoft.winui', '$(MicrosoftWinUIVersion)'))</PkgMicrosoft_WinUI>
</PropertyGroup>
<ItemGroup>
<!--Explicitly reference WinUI winmds from TFM uap10.0-->
<CsWinRTInputs Include="$(PkgMicrosoft_WinUI)/**/*.winmd" />
</ItemGroup>

</Project>
16 changes: 16 additions & 0 deletions src/Tests/TestComponentCSharp/AnotherAssembly.SetPropertyClass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "pch.h"
#include "AnotherAssembly.SetPropertyClass.h"
#include "AnotherAssembly.SetPropertyClass.g.cpp"

namespace winrt::TestComponentCSharp::AnotherAssembly::implementation
{
void SetPropertyClass::ReadWriteProperty(int32_t value)
{
readWriteValue = value;
}

int32_t SetPropertyClass::ReadWriteProperty()
{
return readWriteValue;
}
}
21 changes: 21 additions & 0 deletions src/Tests/TestComponentCSharp/AnotherAssembly.SetPropertyClass.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once
#include "AnotherAssembly.SetPropertyClass.g.h"

namespace winrt::TestComponentCSharp::AnotherAssembly::implementation
{
struct SetPropertyClass : SetPropertyClassT<SetPropertyClass>
{
SetPropertyClass() = default;

void ReadWriteProperty(int32_t value);
int32_t ReadWriteProperty();

int32_t readWriteValue;
};
}
namespace winrt::TestComponentCSharp::AnotherAssembly::factory_implementation
{
struct SetPropertyClass : SetPropertyClassT<SetPropertyClass, implementation::SetPropertyClass>
{
};
}
10 changes: 10 additions & 0 deletions src/Tests/TestComponentCSharp/TestComponentCSharp.idl
Original file line number Diff line number Diff line change
Expand Up @@ -562,4 +562,14 @@ And this is another one"
{
};
}

namespace AnotherAssembly
{
[default_interface]
runtimeclass SetPropertyClass : TestComponentCSharp.IProperties1
{
SetPropertyClass();
Int32 ReadWriteProperty{ set; };
}
}
}
2 changes: 2 additions & 0 deletions src/Tests/TestComponentCSharp/TestComponentCSharp.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="ABCDEFGHIJKLMNOPQRSTUVQXYZabcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMNOPQRSTUVQXYZabcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.h" />
<ClInclude Include="AnotherAssembly.SetPropertyClass.h" />
<ClInclude Include="ManualProjectionTestClasses.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="Class.h">
Expand All @@ -91,6 +92,7 @@
<ItemGroup>
<ClCompile Include="$(GeneratedFilesDir)module.g.cpp" />
<ClCompile Include="ABCDEFGHIJKLMNOPQRSTUVQXYZabcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMNOPQRSTUVQXYZabcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.cpp" />
<ClCompile Include="AnotherAssembly.SetPropertyClass.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<ClCompile Include="Singleton.cpp" />
<ClCompile Include="Windows.Class.cpp" />
<ClCompile Include="ABCDEFGHIJKLMNOPQRSTUVQXYZabcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMNOPQRSTUVQXYZabcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.cpp" />
<ClCompile Include="AnotherAssembly.SetPropertyClass.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
Expand All @@ -29,6 +30,7 @@
<ClInclude Include="Singleton.h" />
<ClInclude Include="Windows.Class.h" />
<ClInclude Include="ABCDEFGHIJKLMNOPQRSTUVQXYZabcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMNOPQRSTUVQXYZabcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.h" />
<ClInclude Include="AnotherAssembly.SetPropertyClass.h" />
</ItemGroup>
<ItemGroup>
<Midl Include="TestComponentCSharp.idl" />
Expand Down
11 changes: 11 additions & 0 deletions src/Tests/UnitTest/TestComponentCSharp_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2432,6 +2432,17 @@ public void TestInterfaceObjectMarshalling()
TestObject.CopyProperties(nativeProperties);

Assert.Equal(TestObject.ReadWriteProperty, nativeProperties.ReadWriteProperty);
}

[Fact]
public void TestSetPropertyAcrossProjections()
{
var setPropertyClass = new TestComponentCSharp.AnotherAssembly.SetPropertyClass();
setPropertyClass.ReadWriteProperty = 4;
Assert.Equal(4, setPropertyClass.ReadWriteProperty);

IProperties1 property = setPropertyClass;
Assert.Equal(4, property.ReadWriteProperty);
}

// Test scenario where type reported by runtimeclass name is not a valid type (i.e. internal type).
Expand Down
1 change: 1 addition & 0 deletions src/Tests/UnitTest/UnitTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Projections\TestSubset\TestSubset.csproj" />
<ProjectReference Include="..\..\Projections\Windows\Windows.csproj" />
<ProjectReference Include="..\..\Projections\WinUI\WinUI.csproj" />
<ProjectReference Include="..\..\Projections\Test\Test.csproj" />
Expand Down
15 changes: 15 additions & 0 deletions src/cswinrt.sln
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IIDOptimizer", "Perf\IIDOpt
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Reunion", "Projections\Reunion\Reunion.csproj", "{B6312AD1-A59E-4F3B-AA39-20B780FE9E15}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestSubset", "Projections\TestSubset\TestSubset.csproj", "{80F0EC48-5536-49D6-8ED1-B1F4CED88073}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM = Debug|ARM
Expand Down Expand Up @@ -482,6 +484,18 @@ Global
{B6312AD1-A59E-4F3B-AA39-20B780FE9E15}.Release|x64.Build.0 = Release|x64
{B6312AD1-A59E-4F3B-AA39-20B780FE9E15}.Release|x86.ActiveCfg = Release|x86
{B6312AD1-A59E-4F3B-AA39-20B780FE9E15}.Release|x86.Build.0 = Release|x86
{80F0EC48-5536-49D6-8ED1-B1F4CED88073}.Debug|ARM.ActiveCfg = Debug|x86
{80F0EC48-5536-49D6-8ED1-B1F4CED88073}.Debug|ARM64.ActiveCfg = Debug|x86
{80F0EC48-5536-49D6-8ED1-B1F4CED88073}.Debug|x64.ActiveCfg = Debug|x64
{80F0EC48-5536-49D6-8ED1-B1F4CED88073}.Debug|x64.Build.0 = Debug|x64
{80F0EC48-5536-49D6-8ED1-B1F4CED88073}.Debug|x86.ActiveCfg = Debug|x86
{80F0EC48-5536-49D6-8ED1-B1F4CED88073}.Debug|x86.Build.0 = Debug|x86
{80F0EC48-5536-49D6-8ED1-B1F4CED88073}.Release|ARM.ActiveCfg = Release|x86
{80F0EC48-5536-49D6-8ED1-B1F4CED88073}.Release|ARM64.ActiveCfg = Release|x86
{80F0EC48-5536-49D6-8ED1-B1F4CED88073}.Release|x64.ActiveCfg = Release|x64
{80F0EC48-5536-49D6-8ED1-B1F4CED88073}.Release|x64.Build.0 = Release|x64
{80F0EC48-5536-49D6-8ED1-B1F4CED88073}.Release|x86.ActiveCfg = Release|x86
{80F0EC48-5536-49D6-8ED1-B1F4CED88073}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -509,6 +523,7 @@ Global
{493C7729-2F21-4198-AB09-BDF56BF501D3} = {CFB651EC-DAA4-4A11-ABCD-C77F90602EB5}
{AE3B0611-2FBB-42AB-A245-B4E79868A5F9} = {539DBDEF-3B49-4503-9BD3-7EB83C2179CB}
{B6312AD1-A59E-4F3B-AA39-20B780FE9E15} = {6D41796B-9904-40B8-BBCB-40B2D1BAE44B}
{80F0EC48-5536-49D6-8ED1-B1F4CED88073} = {6D41796B-9904-40B8-BBCB-40B2D1BAE44B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5AE8C9D7-2613-4E1A-A4F2-579BAC28D0A2}
Expand Down
4 changes: 3 additions & 1 deletion src/cswinrt/code_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -3457,7 +3457,9 @@ global::System.Collections.Concurrent.ConcurrentDictionary<RuntimeTypeHandle, ob
if (!getter)
{
auto getter_interface = write_type_name_temp(w,
find_property_interface(w, type, prop.Name()).first, "%", typedef_name_type::ABI);
find_property_interface(w, type, prop.Name()).first,
"%",
settings.netstandard_compat ? typedef_name_type::ABI : typedef_name_type::CCW);
auto getter_cast = settings.netstandard_compat ? "As<%>()"s : "((%)(IWinRTObject)this)"s;
w.write("get{ return " + getter_cast + ".%; }\n", getter_interface, prop.Name());
}
Expand Down

0 comments on commit 26943b2

Please sign in to comment.