From b92b31143c96aa9b413a5502be1c51780995f142 Mon Sep 17 00:00:00 2001 From: Johan Laanstra <jlaans@microsoft.com> Date: Mon, 5 Feb 2024 10:56:09 -0800 Subject: [PATCH] Fix mising global:: and add test case to avoid breaking in future. --- .../TestComponentCSharp.idl | 12 +++++++++++ .../TestComponentCSharp.vcxproj | 2 ++ src/Tests/TestComponentCSharp/WinRT.Class.cpp | 18 +++++++++++++++++ src/Tests/TestComponentCSharp/WinRT.Class.h | 20 +++++++++++++++++++ src/cswinrt/code_writers.h | 2 +- 5 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/Tests/TestComponentCSharp/WinRT.Class.cpp create mode 100644 src/Tests/TestComponentCSharp/WinRT.Class.h diff --git a/src/Tests/TestComponentCSharp/TestComponentCSharp.idl b/src/Tests/TestComponentCSharp/TestComponentCSharp.idl index a30a24798..c5be66f41 100644 --- a/src/Tests/TestComponentCSharp/TestComponentCSharp.idl +++ b/src/Tests/TestComponentCSharp/TestComponentCSharp.idl @@ -650,6 +650,18 @@ And this is another one" }; } + // Compile time test for sub WinRT namespace + namespace WinRT + { + runtimeclass Class + { + Class(); + static void StaticMethod(); + void Method(); + void Method2(Windows.Foundation.IStringable stringable); + } + } + namespace AnotherAssembly { [default_interface] diff --git a/src/Tests/TestComponentCSharp/TestComponentCSharp.vcxproj b/src/Tests/TestComponentCSharp/TestComponentCSharp.vcxproj index 8f6a8028d..fe9013635 100644 --- a/src/Tests/TestComponentCSharp/TestComponentCSharp.vcxproj +++ b/src/Tests/TestComponentCSharp/TestComponentCSharp.vcxproj @@ -94,6 +94,7 @@ <ClInclude Include="WarningClass.h" /> <ClInclude Include="WarningStatic.h" /> <ClInclude Include="Windows.Class.h" /> + <ClInclude Include="WinRT.Class.h" /> </ItemGroup> <ItemGroup> <ClCompile Include="$(GeneratedFilesDir)module.g.cpp" /> @@ -114,6 +115,7 @@ <ClCompile Include="WarningClass.cpp" /> <ClCompile Include="WarningStatic.cpp" /> <ClCompile Include="Windows.Class.cpp" /> + <ClCompile Include="WinRT.Class.cpp" /> </ItemGroup> <ItemGroup> <Midl Include="TestComponentCSharp.idl" /> diff --git a/src/Tests/TestComponentCSharp/WinRT.Class.cpp b/src/Tests/TestComponentCSharp/WinRT.Class.cpp new file mode 100644 index 000000000..309766d4a --- /dev/null +++ b/src/Tests/TestComponentCSharp/WinRT.Class.cpp @@ -0,0 +1,18 @@ +#include "pch.h" +#include "WinRT.Class.h" +#include "WinRT.Class.g.cpp" + +namespace winrt::TestComponentCSharp::WinRT::implementation +{ + void Class::StaticMethod() + { + } + + void Class::Method() + { + } + + void Class::Method2(winrt::Windows::Foundation::IStringable const& stringable) + { + } +} diff --git a/src/Tests/TestComponentCSharp/WinRT.Class.h b/src/Tests/TestComponentCSharp/WinRT.Class.h new file mode 100644 index 000000000..809f6153b --- /dev/null +++ b/src/Tests/TestComponentCSharp/WinRT.Class.h @@ -0,0 +1,20 @@ +#pragma once +#include "WinRT.Class.g.h" + +namespace winrt::TestComponentCSharp::WinRT::implementation +{ + struct Class : ClassT<Class> + { + Class() = default; + + static void StaticMethod(); + void Method(); + void Method2(winrt::Windows::Foundation::IStringable const& stringable); + }; +} +namespace winrt::TestComponentCSharp::WinRT::factory_implementation +{ + struct Class : ClassT<Class, implementation::Class> + { + }; +} diff --git a/src/cswinrt/code_writers.h b/src/cswinrt/code_writers.h index 7f183af20..9ae6c4844 100644 --- a/src/cswinrt/code_writers.h +++ b/src/cswinrt/code_writers.h @@ -2074,7 +2074,7 @@ ComWrappersSupport.RegisterObjectForInterface(this, ThisPtr); auto objrefname = w.write_temp("%", bind<write_objref_type_name>(class_type)); w.write(R"( -public %() : this(%(WinRT.IActivationFactoryMethods.ActivateInstance<IUnknownVftbl>(%))) +public %() : this(%(global::WinRT.IActivationFactoryMethods.ActivateInstance<IUnknownVftbl>(%))) { ComWrappersSupport.RegisterObjectForInterface(this, ThisPtr); %