Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Tests/TestComponentCSharp/TestComponentCSharp.idl
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,9 @@ namespace TestComponentCSharp
overridable Int32 WarningOverridableProperty;
// see https://github.com/microsoft/cppwinrt/issues/782
//overridable event Windows.Foundation.EventHandler<Int32> WarningOverridableEvent;
Int32 CallOverridablePropertyGetter();
void CallOverridablePropertySetter(Int32 value);
void CallOverridableMethod();
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/Tests/TestComponentCSharp/WarningClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ namespace winrt::TestComponentCSharp::implementation
void WarningClass::WarningOverridableProperty(int32_t value)
{
}
int32_t WarningClass::CallOverridablePropertyGetter()
{
return overridable().WarningOverridableProperty();
}
void WarningClass::CallOverridablePropertySetter(int32_t value)
{
overridable().WarningOverridableProperty(value);
}
void WarningClass::CallOverridableMethod()
{
overridable().WarningOverridableMethod();
}
//winrt::event_token WarningClass::WarningOverridableEvent(Windows::Foundation::EventHandler<int32_t> const& handler)
//{
// return {};
Expand Down
3 changes: 3 additions & 0 deletions src/Tests/TestComponentCSharp/WarningClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ namespace winrt::TestComponentCSharp::implementation
void WarningOverridableMethod();
int32_t WarningOverridableProperty();
void WarningOverridableProperty(int32_t value);
int32_t CallOverridablePropertyGetter();
void CallOverridablePropertySetter(int32_t value);
void CallOverridableMethod();
//winrt::event_token WarningOverridableEvent(Windows::Foundation::EventHandler<int32_t> const& handler);
//void WarningOverridableEvent(winrt::event_token const& token) noexcept;
int32_t WarningInterfacePropertySetter();
Expand Down
35 changes: 35 additions & 0 deletions src/Tests/UnitTest/TestComponentCSharp_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3553,6 +3553,41 @@ private void TestSupportedOSPlatformWarnings()
}
#endif

#if NET
[Fact]
public void TestOverridable()
{
var obj = new OverridableTestClass();

// Test overridable property round-trip through native overrides interface
Assert.Equal(42, obj.CallOverridablePropertyGetter());
obj.CallOverridablePropertySetter(99);
Assert.Equal(99, obj.CallOverridablePropertyGetter());

// Test overridable method round-trip through native overrides interface
Assert.False(obj.MethodWasCalled);
obj.CallOverridableMethod();
Assert.True(obj.MethodWasCalled);
}

class OverridableTestClass : WarningClass
{
private int _value = 42;
public bool MethodWasCalled { get; private set; }

protected override int WarningOverridableProperty
{
get => _value;
set => _value = value;
}

protected override void WarningOverridableMethod()
{
MethodWasCalled = true;
}
}
#endif

[Fact]
public void TestObjectFunctions()
{
Expand Down
32 changes: 23 additions & 9 deletions src/cswinrt/code_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -3395,15 +3395,22 @@ private % AsInternal(InterfaceTag<%> _) => % ?? Make_%();
if (getter || base_getter)
{
w.write("%get => %; ", base_getter_platform_attribute, bind([&](writer& w) {
if (call_static_method)
if (is_private)
{
auto iface = base_getter ? getter_property_iface : prop.Parent();
w.write("%", bind<write_abi_get_property_static_method_call>(iface, prop,
w.write_temp("%", bind<write_objref_type_name>(iface))));
if (call_static_method)
{
auto iface = base_getter ? getter_property_iface : prop.Parent();
w.write("%", bind<write_abi_get_property_static_method_call>(iface, prop,
w.write_temp("%", bind<write_objref_type_name>(iface))));
}
else
{
w.write("%.%", target, prop.Name());
}
}
else
{
w.write("%%", is_private ? target + "." : "", prop.Name());
w.write("%", prop.Name());
}
}));
}
Expand All @@ -3413,14 +3420,21 @@ private % AsInternal(InterfaceTag<%> _) => % ?? Make_%();
if (setter)
{
w.write("set => %;", bind([&](writer& w) {
if (call_static_method)
if (is_private)
{
w.write("%", bind<write_abi_set_property_static_method_call>(prop.Parent(), prop,
w.write_temp("%", bind<write_objref_type_name>(prop.Parent()))));
if (call_static_method)
{
w.write("%", bind<write_abi_set_property_static_method_call>(prop.Parent(), prop,
w.write_temp("%", bind<write_objref_type_name>(prop.Parent()))));
}
else
{
w.write("%.% = value", target, prop.Name());
}
}
else
{
w.write("%% = value", is_private ? target + "." : "", prop.Name());
w.write("% = value", prop.Name());
}
}));
}
Expand Down
Loading