Support getting the base type.

This commit is contained in:
Paul Knopf 2018-12-30 21:44:41 -05:00
parent a66405bccb
commit ac81a06787
5 changed files with 85 additions and 15 deletions

View file

@ -28,6 +28,16 @@ QString NetTypeInfo::getFullTypeName() {
return _fullTypeName;
}
QString NetTypeInfo::getBaseType() const
{
return _baseType;
}
void NetTypeInfo::setBaseType(const QString& baseType)
{
_baseType = baseType;
}
QString NetTypeInfo::getClassName() {
return _className;
}
@ -190,6 +200,21 @@ Q_DECL_EXPORT QmlNetStringContainer* type_info_getFullTypeName(NetTypeInfoContai
return createString(result);
}
Q_DECL_EXPORT QmlNetStringContainer* type_info_getBaseType(NetTypeInfoContainer* netTypeInfo)
{
auto result = netTypeInfo->netTypeInfo->getBaseType();
return createString(result);
}
Q_DECL_EXPORT void type_info_setBaseType(NetTypeInfoContainer* netTypeInfo, LPWCSTR baseType)
{
if(baseType == nullptr) {
netTypeInfo->netTypeInfo->setBaseType(QString());
} else {
netTypeInfo->netTypeInfo->setBaseType(QString::fromUtf16(baseType));
}
}
Q_DECL_EXPORT QmlNetStringContainer* type_info_getClassName(NetTypeInfoContainer* netTypeInfo) {
QString result = netTypeInfo->netTypeInfo->getClassName();
return createString(result);

View file

@ -19,6 +19,9 @@ public:
QString getFullTypeName();
QString getBaseType() const;
void setBaseType(const QString& baseType);
QString getClassName();
void setClassName(QString className);
@ -59,6 +62,7 @@ public:
private:
QString _fullTypeName;
QString _baseType;
QString _className;
NetVariantTypeEnum _variantType;
bool _isArray;

View file

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using FluentAssertions;
using Qml.Net.Internal.Types;
@ -298,5 +298,24 @@ namespace Qml.Net.Tests.Types
}
}
}
public class TestType15
{
}
public class TestType16 : TestType15
{
}
[Fact]
public void Can_detect_base_class()
{
var type1 = NetTypeManager.GetTypeInfo<TestType15>();
type1.BaseType.Should().StartWith("System.Object, ");
var type2 = NetTypeManager.GetTypeInfo<TestType16>();
type2.BaseType.Should().StartWith("Qml.Net.Tests.Types.NetTypeManagerTests+TestType15, ");
var type3 = NetTypeManager.GetTypeInfo<object>();
type3.BaseType.Should().BeNull();
}
}
}

View file

@ -29,6 +29,12 @@ namespace Qml.Net.Internal
throw new InvalidOperationException();
}
var baseType = typeInfo.BaseType;
if (baseType != null)
{
type.BaseType = baseType.AssemblyQualifiedName;
}
type.ClassName = typeInfo.Name;
type.PrefVariantType = GetPrefVariantType(typeInfo);

View file

@ -17,6 +17,12 @@ namespace Qml.Net.Internal.Types
public string FullTypeName => Utilities.ContainerToString(Interop.NetTypeInfo.GetFullTypeName(Handle));
public string BaseType
{
get => Utilities.ContainerToString(Interop.NetTypeInfo.GetBaseType(Handle));
set => Interop.NetTypeInfo.SetBaseType(Handle, value);
}
public string ClassName
{
get => Utilities.ContainerToString(Interop.NetTypeInfo.GetClassName(Handle));
@ -133,6 +139,16 @@ namespace Qml.Net.Internal.Types
public delegate IntPtr GetFullTypeNameDel(IntPtr netTypeInfo);
[NativeSymbol(Entrypoint = "type_info_getBaseType")]
public GetBaseTypeDel GetBaseType { get; set; }
public delegate IntPtr GetBaseTypeDel(IntPtr netTypeInfo);
[NativeSymbol(Entrypoint = "type_info_setBaseType")]
public SetBaseTypeDel SetBaseType { get; set; }
public delegate void SetBaseTypeDel(IntPtr netTypeInfo, [MarshalAs(UnmanagedType.LPWStr)]string baseType);
[NativeSymbol(Entrypoint = "type_info_setClassName")]
public SetClassNameDel SetClassName { get; set; }