Fixed issue with dynamic method invocations on QObjects not working.

This commit is contained in:
Paul Knopf 2019-04-23 08:12:20 -04:00
parent ff203ceb3e
commit 62c8b9f47b
2 changed files with 32 additions and 14 deletions

View file

@ -130,6 +130,17 @@ namespace Qml.Net.Tests.Qml
});
}
[Fact]
public void Can_invoke_method_on_qobject_as_dynamic()
{
AssertQObject(qObject =>
{
var d = (dynamic)qObject;
var result = (int)d.testSlotInt(23);
result.Should().Be(23);
});
}
[Fact]
public void Can_set_random_types_on_property()
{

View file

@ -113,20 +113,6 @@ namespace Qml.Net.Internal.Qml
public NetQObject QObject => _qObject;
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
result = GetProperty(binder.Name);
// TODO: Check if this was actually a property
return true;
}
public override bool TrySetMember(SetMemberBinder binder, object value)
{
SetProperty(binder.Name, value);
// TODO: Check if this was actually a property
return true;
}
public object GetProperty(string propertyName)
{
var property = _qObject.GetProperty(propertyName);
@ -232,6 +218,27 @@ namespace Qml.Net.Internal.Qml
return _qObject.AttachNotifySignal(propertyName, del);
}
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
result = GetProperty(binder.Name);
// TODO: Check if this was actually a property
return true;
}
public override bool TrySetMember(SetMemberBinder binder, object value)
{
SetProperty(binder.Name, value);
// TODO: Check if this was actually a property
return true;
}
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
{
result = InvokeMethod(binder.Name, args);
// TODO: Check if this was actually a method.
return true;
}
}
}