Skip to content

Commit

Permalink
Add missing MarshalInspectable methods (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
Scottj1s authored Apr 27, 2020
1 parent 21b81cf commit 80297f5
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
27 changes: 27 additions & 0 deletions TestComponentCSharp/Class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,33 @@ namespace winrt::TestComponentCSharp::implementation
{
_objectChanged.remove(token);
}
Windows::Foundation::Collections::IIterable<Windows::Foundation::IInspectable> Class::ObjectIterableProperty()
{
return _objectIterable;
}
void Class::ObjectIterableProperty(Windows::Foundation::Collections::IIterable<Windows::Foundation::IInspectable> const& value)
{
for (auto element : value)
{
}
_objectIterable = value;
}
void Class::RaiseObjectIterableChanged()
{
_objectIterableChanged(*this, _objectIterable);
}
void Class::CallForObjectIterable(TestComponentCSharp::ProvideObjectIterable const& provideObjectIterable)
{
_objectIterable = provideObjectIterable();
}
winrt::event_token Class::ObjectIterablePropertyChanged(Windows::Foundation::EventHandler<Windows::Foundation::Collections::IIterable<Windows::Foundation::IInspectable>> const& handler)
{
return _objectIterableChanged.add(handler);
}
void Class::ObjectIterablePropertyChanged(winrt::event_token const& token) noexcept
{
_objectIterableChanged.remove(token);
}
Uri Class::UriProperty()
{
return _uri;
Expand Down
8 changes: 8 additions & 0 deletions TestComponentCSharp/Class.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace winrt::TestComponentCSharp::implementation
Windows::Foundation::Collections::IVector<hstring> _strings;
Windows::Foundation::IInspectable _object;
winrt::event<Windows::Foundation::EventHandler<Windows::Foundation::IInspectable>> _objectChanged;
Windows::Foundation::Collections::IIterable<Windows::Foundation::IInspectable> _objectIterable;
winrt::event<Windows::Foundation::EventHandler<Windows::Foundation::Collections::IIterable<Windows::Foundation::IInspectable>>> _objectIterableChanged;
Windows::Foundation::Uri _uri;
winrt::event<Windows::Foundation::EventHandler<Windows::Foundation::Uri>> _uriChanged;
Windows::Foundation::Collections::IKeyValuePair<hstring, hstring> _stringPair;
Expand Down Expand Up @@ -131,6 +133,12 @@ namespace winrt::TestComponentCSharp::implementation
void RaiseObjectChanged();
void CallForObject(TestComponentCSharp::ProvideObject const& provideObject);
winrt::event_token ObjectPropertyChanged(Windows::Foundation::EventHandler<Windows::Foundation::IInspectable> const& handler);
Windows::Foundation::Collections::IIterable<Windows::Foundation::IInspectable> ObjectIterableProperty();
void ObjectIterableProperty(Windows::Foundation::Collections::IIterable<Windows::Foundation::IInspectable> const& value);
void RaiseObjectIterableChanged();
void CallForObjectIterable(TestComponentCSharp::ProvideObjectIterable const& provideObjectIterable);
winrt::event_token ObjectIterablePropertyChanged(Windows::Foundation::EventHandler<Windows::Foundation::Collections::IIterable<Windows::Foundation::IInspectable>> const& handler);
void ObjectIterablePropertyChanged(winrt::event_token const& token) noexcept;
Windows::Foundation::Uri UriProperty();
void UriProperty(Windows::Foundation::Uri const& value);
void RaiseUriChanged();
Expand Down
8 changes: 7 additions & 1 deletion TestComponentCSharp/TestComponentCSharp.idl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace TestComponentCSharp
delegate Boolean ProvideBool();
delegate String ProvideString();
delegate Object ProvideObject();
delegate Windows.Foundation.Collections.IIterable<Object> ProvideObjectIterable();
delegate Windows.Foundation.Uri ProvideUri();
delegate Windows.Foundation.Collections.IKeyValuePair<String, String> ProvideStringPair();
delegate Microsoft.UI.Xaml.Interop.IBindableIterable ProvideBindableIterable();
Expand Down Expand Up @@ -158,6 +159,11 @@ namespace TestComponentCSharp
void CallForObject(ProvideObject provideObject);
event Windows.Foundation.EventHandler<Object> ObjectPropertyChanged;

Windows.Foundation.Collections.IIterable<Object> ObjectIterableProperty;
void RaiseObjectIterableChanged();
void CallForObjectIterable(ProvideObjectIterable provideObjectIterable);
event Windows.Foundation.EventHandler<Windows.Foundation.Collections.IIterable<Object> > ObjectIterablePropertyChanged;

Windows.Foundation.Uri UriProperty;
void RaiseUriChanged();
void CallForUri(ProvideUri provideUri);
Expand Down Expand Up @@ -218,7 +224,7 @@ namespace TestComponentCSharp

Windows.Foundation.Collections.IIterable<Int32> GetIntIterable();
void SetIntIterable(Windows.Foundation.Collections.IIterable<Int32> value);

// Bindable
Microsoft.UI.Xaml.Interop.IBindableIterable BindableIterableProperty;
void RaiseBindableIterableChanged();
Expand Down
4 changes: 4 additions & 0 deletions UnitTest/TestComponentCSharp_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ public void TestObjectCasting()
TestObject.ObjectProperty = strings_in;
strings_out = (string[])TestObject.ObjectProperty;
Assert.True(strings_out.SequenceEqual(strings_in));

var objects = new List<ManagedType>() { new ManagedType(), new ManagedType() };
var query = from item in objects select item;
TestObject.ObjectIterableProperty = query;
}

[Fact]
Expand Down
2 changes: 2 additions & 0 deletions WinRT.Runtime/Marshalers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,8 @@ static Marshaler()
CreateMarshaler = (T value) => MarshalInspectable.CreateMarshaler(value);
GetAbi = (object objRef) => MarshalInspectable.GetAbi((IObjectReference)objRef);
FromAbi = (object box) => (T)MarshalInspectable.FromAbi((IntPtr)box);
FromManaged = (T value) => MarshalInspectable.FromManaged(value);
CopyManaged = (T value, IntPtr dest) => MarshalInspectable.CopyManaged(value, dest);
DisposeMarshaler = (object objRef) => MarshalInspectable.DisposeMarshaler((IObjectReference)objRef);
DisposeAbi = (object box) => MarshalInspectable.DisposeAbi((IntPtr)box);
}
Expand Down

0 comments on commit 80297f5

Please sign in to comment.