From 6d5bff37e365a0e8e68426c30a4cda01303836c8 Mon Sep 17 00:00:00 2001 From: Manodasan Wignarajah Date: Wed, 1 Feb 2023 12:51:12 -0800 Subject: [PATCH] Add using for system name to event helpers file (#1288) --- src/Tests/TestComponentCSharp/Class.cpp | 16 ++++++++++++++++ src/Tests/TestComponentCSharp/Class.h | 5 +++++ .../TestComponentCSharp/TestComponentCSharp.idl | 4 ++++ src/cswinrt/main.cpp | 2 +- 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Tests/TestComponentCSharp/Class.cpp b/src/Tests/TestComponentCSharp/Class.cpp index d299fa692..ff14e066a 100644 --- a/src/Tests/TestComponentCSharp/Class.cpp +++ b/src/Tests/TestComponentCSharp/Class.cpp @@ -298,6 +298,18 @@ namespace winrt::TestComponentCSharp::implementation { _collectionEvent(sender, arg0, arg1); } + winrt::event_token Class::GuidEvent(TestComponentCSharp::EventWithGuid const& handler) + { + return _guidEvent.add(handler); + } + void Class::GuidEvent(winrt::event_token const& token) noexcept + { + _guidEvent.remove(token); + } + void Class::InvokeGuidEvent(winrt::guid const& correlationGuid) + { + _guidEvent(correlationGuid); + } winrt::event_token Class::NestedEvent(EventHandler> const& handler) { return _nestedEvent.add(handler); @@ -335,6 +347,10 @@ namespace winrt::TestComponentCSharp::implementation _returnEvent(arg0); return arg0; } + winrt::guid Class::TestReturnGuid(winrt::guid const& arg) + { + return arg; + } int32_t Class::IntProperty() { return _int; diff --git a/src/Tests/TestComponentCSharp/Class.h b/src/Tests/TestComponentCSharp/Class.h index 6604e896f..c3a070c12 100644 --- a/src/Tests/TestComponentCSharp/Class.h +++ b/src/Tests/TestComponentCSharp/Class.h @@ -20,6 +20,7 @@ namespace winrt::TestComponentCSharp::implementation winrt::event _event2; winrt::event _event3; winrt::event _collectionEvent; + winrt::event _guidEvent; winrt::event>> _nestedEvent; winrt::event>> _nestedTypedEvent; winrt::event _returnEvent; @@ -124,6 +125,9 @@ namespace winrt::TestComponentCSharp::implementation winrt::event_token CollectionEvent(TestComponentCSharp::EventHandlerCollection const& handler); void CollectionEvent(winrt::event_token const& token) noexcept; void InvokeCollectionEvent(TestComponentCSharp::Class const& sender, Windows::Foundation::Collections::IVector const& arg0, Windows::Foundation::Collections::IMap const& arg1); + winrt::event_token GuidEvent(TestComponentCSharp::EventWithGuid const& handler); + void GuidEvent(winrt::event_token const& token) noexcept; + void InvokeGuidEvent(winrt::guid const& correlationGuid); winrt::event_token NestedEvent(Windows::Foundation::EventHandler> const& handler); void NestedEvent(winrt::event_token const& token) noexcept; void InvokeNestedEvent(TestComponentCSharp::Class const& sender, Windows::Foundation::Collections::IVector const& arg0); @@ -133,6 +137,7 @@ namespace winrt::TestComponentCSharp::implementation winrt::event_token ReturnEvent(TestComponentCSharp::EventWithReturn const& handler); void ReturnEvent(winrt::event_token const& token) noexcept; int32_t InvokeReturnEvent(int32_t const& arg0); + winrt::guid TestReturnGuid(winrt::guid const& arg); int32_t IntProperty(); void IntProperty(int32_t value); diff --git a/src/Tests/TestComponentCSharp/TestComponentCSharp.idl b/src/Tests/TestComponentCSharp/TestComponentCSharp.idl index 17af1636b..db82aab16 100644 --- a/src/Tests/TestComponentCSharp/TestComponentCSharp.idl +++ b/src/Tests/TestComponentCSharp/TestComponentCSharp.idl @@ -12,6 +12,7 @@ namespace TestComponentCSharp delegate void EventHandler3(Class sender, Int32 arg0, String arg1); delegate void EventHandlerCollection(Class sender, Windows.Foundation.Collections.IVector arg0, Windows.Foundation.Collections.IMap arg1); delegate Int32 EventWithReturn(Int32 arg); + delegate void EventWithGuid(Guid correlationGuid); [flags] enum FlagValue @@ -184,13 +185,16 @@ namespace TestComponentCSharp event EventHandler3 Event3; void InvokeEvent3(Class sender, Int32 arg0, String arg1); event EventHandlerCollection CollectionEvent; + event EventWithGuid GuidEvent; void InvokeCollectionEvent(Class sender, Windows.Foundation.Collections.IVector arg0, Windows.Foundation.Collections.IMap arg1); + void InvokeGuidEvent(Guid correlationGuid); event Windows.Foundation.EventHandler > NestedEvent; void InvokeNestedEvent(Class sender, Windows.Foundation.Collections.IVector arg0); event Windows.Foundation.TypedEventHandler > NestedTypedEvent; void InvokeNestedTypedEvent(Class sender, Windows.Foundation.Collections.IVector arg0); event EventWithReturn ReturnEvent; Int32 InvokeReturnEvent(Int32 arg0); + Guid TestReturnGuid(Guid arg); Int32 IntProperty; event Windows.Foundation.EventHandler IntPropertyChanged; diff --git a/src/cswinrt/main.cpp b/src/cswinrt/main.cpp index a407ba43f..e0741217a 100644 --- a/src/cswinrt/main.cpp +++ b/src/cswinrt/main.cpp @@ -343,7 +343,7 @@ Where is one or more of: writer eventHelperWriter("WinRT"); write_file_header(eventHelperWriter); - eventHelperWriter.write("namespace WinRT\n{\n%\n}", bind([&](writer& w) { + eventHelperWriter.write("using System;\nnamespace WinRT\n{\n%\n}", bind([&](writer& w) { for (auto&& [key, value] : typeNameToEventDefinitionMap) { w.write("%", value);