mirror of
https://github.com/qmlnet/qmlnet.git
synced 2026-05-21 06:45:32 -06:00
Added support for discovering signals on the type info.
This commit is contained in:
parent
cf8abed344
commit
eda3d26031
3 changed files with 50 additions and 0 deletions
|
|
@ -130,6 +130,25 @@ namespace Qt.NetCore.Tests.Types
|
|||
property.ParentType.ClassName.Should().Be("TestType6");
|
||||
}
|
||||
|
||||
[Signal("testSignal", NetVariantType.DateTime, NetVariantType.Object)]
|
||||
public class TestType7
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Can_get_signal()
|
||||
{
|
||||
var type = NetTypeManager.GetTypeInfo<TestType7>();
|
||||
|
||||
type.SignalCount.Should().Be(1);
|
||||
var signal = type.GetSignal(0);
|
||||
signal.Name.Should().Be("testSignal");
|
||||
signal.ParameterCount.Should().Be(2);
|
||||
signal.GetParameter(0).Should().Be(NetVariantType.DateTime);
|
||||
signal.GetParameter(1).Should().Be(NetVariantType.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Null_type_returned_for_invalid_type()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using Qt.NetCore.Qml;
|
||||
|
|
@ -81,6 +82,18 @@ namespace Qt.NetCore.Internal
|
|||
type.AddProperty(property);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var signalAttribute in typeInfo.GetCustomAttributes().OfType<SignalAttribute>())
|
||||
{
|
||||
using (var signal = new NetSignalInfo(signalAttribute.Name))
|
||||
{
|
||||
foreach (var parameter in signalAttribute.Parameters)
|
||||
{
|
||||
signal.AddParameter(parameter);
|
||||
}
|
||||
type.AddSignal(signal);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
18
src/net/Qt.NetCore/SignalAttribute.cs
Normal file
18
src/net/Qt.NetCore/SignalAttribute.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
using System;
|
||||
|
||||
namespace Qt.NetCore
|
||||
{
|
||||
public class SignalAttribute : Attribute
|
||||
{
|
||||
public SignalAttribute(string name, params NetVariantType[] parameters)
|
||||
{
|
||||
Name = name;
|
||||
Parameters = parameters;
|
||||
}
|
||||
|
||||
|
||||
public string Name { get; }
|
||||
|
||||
public NetVariantType[] Parameters { get; }
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue