Added a property to indicate if a method is static.

This commit is contained in:
Paul Knopf 2018-08-17 22:06:37 -04:00
parent d2ae229000
commit a975a261eb
5 changed files with 50 additions and 11 deletions

View file

@ -21,10 +21,12 @@ QSharedPointer<NetTypeInfo> NetMethodInfoArguement::getType()
NetMethodInfo::NetMethodInfo(QSharedPointer<NetTypeInfo> parentTypeInfo,
QString methodName,
QSharedPointer<NetTypeInfo> returnType) :
QSharedPointer<NetTypeInfo> returnType,
bool isStatic) :
_parentTypeInfo(parentTypeInfo),
_methodName(methodName),
_returnType(returnType)
_returnType(returnType),
_isStatic(isStatic)
{
}
@ -38,6 +40,11 @@ QSharedPointer<NetTypeInfo> NetMethodInfo::getReturnType()
return _returnType;
}
bool NetMethodInfo::isStatic()
{
return _isStatic;
}
void NetMethodInfo::addParameter(QString name, QSharedPointer<NetTypeInfo> typeInfo)
{
_parameters.append(QSharedPointer<NetMethodInfoArguement>(new NetMethodInfoArguement(name, typeInfo)));
@ -100,7 +107,7 @@ Q_DECL_EXPORT NetTypeInfoContainer* method_info_parameter_getType(NetMethodInfoA
return result;
}
Q_DECL_EXPORT NetMethodInfoContainer* method_info_create(NetTypeInfoContainer* parentTypeContainer, LPWSTR methodName, NetTypeInfoContainer* returnTypeContainer)
Q_DECL_EXPORT NetMethodInfoContainer* method_info_create(NetTypeInfoContainer* parentTypeContainer, LPWSTR methodName, NetTypeInfoContainer* returnTypeContainer, bool isStatic)
{
NetMethodInfoContainer* result = new NetMethodInfoContainer();
@ -114,7 +121,7 @@ Q_DECL_EXPORT NetMethodInfoContainer* method_info_create(NetTypeInfoContainer* p
returnType = returnTypeContainer->netTypeInfo;
}
NetMethodInfo* instance = new NetMethodInfo(parentType, QString::fromUtf16((const char16_t*)methodName), returnType);
NetMethodInfo* instance = new NetMethodInfo(parentType, QString::fromUtf16((const char16_t*)methodName), returnType, isStatic);
result->method = QSharedPointer<NetMethodInfo>(instance);
return result;
}
@ -141,6 +148,11 @@ Q_DECL_EXPORT NetTypeInfoContainer* method_info_getReturnType(NetMethodInfoConta
return result;
}
Q_DECL_EXPORT bool method_info_isStatic(NetMethodInfoContainer* container)
{
return container->method->isStatic();
}
Q_DECL_EXPORT void method_info_addParameter(NetMethodInfoContainer* container, LPWSTR name, NetTypeInfoContainer* typeInfoContainer)
{
container->method->addParameter(QString::fromUtf16((const char16_t*)name), typeInfoContainer->netTypeInfo);

View file

@ -20,12 +20,15 @@ class NetMethodInfo {
public:
NetMethodInfo(QSharedPointer<NetTypeInfo> parentTypeInfo,
QString methodName,
QSharedPointer<NetTypeInfo> returnType);
QSharedPointer<NetTypeInfo> returnType,
bool isStatic);
QString getMethodName();
QSharedPointer<NetTypeInfo> getReturnType();
bool isStatic();
void addParameter(QString name, QSharedPointer<NetTypeInfo> typeInfo);
int getParameterCount();
QSharedPointer<NetMethodInfoArguement> getParameter(int index);
@ -36,6 +39,7 @@ private:
QSharedPointer<NetTypeInfo> _parentTypeInfo;
QString _methodName;
QSharedPointer<NetTypeInfo> _returnType;
bool _isStatic;
QList<QSharedPointer<NetMethodInfoArguement>> _parameters;
};

View file

@ -240,5 +240,21 @@ namespace Qml.Net.Tests.Types
method.ReturnType.MethodCount.Should().Be(0);
method.ReturnType.IsLoaded.Should().BeTrue();
}
public class TestType12
{
public void Method()
{
}
}
[Fact]
public void Can_detect_non_static_methods()
{
var type = NetTypeManager.GetTypeInfo<TestType12>();
type.EnsureLoaded();
type.GetMethod(0).IsStatic.Should().BeFalse();
}
}
}

View file

@ -60,7 +60,7 @@ namespace Qml.Net.Internal
NetTypeManager.GetTypeInfo(methodInfo.ReturnParameter.ParameterType);
}
var method = new NetMethodInfo(type, methodInfo.Name, returnType);
var method = new NetMethodInfo(type, methodInfo.Name, returnType, false);
foreach (var parameter in methodInfo.GetParameters())
{

View file

@ -10,8 +10,9 @@ namespace Qml.Net.Internal.Types
{
public NetMethodInfo(NetTypeInfo parentTypeInfo,
string methodName,
NetTypeInfo returnTypeInfo)
: this(Create(parentTypeInfo, methodName, returnTypeInfo))
NetTypeInfo returnTypeInfo,
bool isStatic)
: this(Create(parentTypeInfo, methodName, returnTypeInfo, isStatic))
{
}
@ -24,11 +25,13 @@ namespace Qml.Net.Internal.Types
private static IntPtr Create(NetTypeInfo parentTypeInfo,
string methodName,
NetTypeInfo returnTypeInfo)
NetTypeInfo returnTypeInfo,
bool isStatic)
{
return Interop.NetMethodInfo.Create(parentTypeInfo?.Handle ?? IntPtr.Zero,
methodName,
returnTypeInfo?.Handle ?? IntPtr.Zero);
returnTypeInfo?.Handle ?? IntPtr.Zero,
isStatic);
}
public string MethodName => Utilities.ContainerToString(Interop.NetMethodInfo.GetMethodName(Handle));
@ -43,6 +46,8 @@ namespace Qml.Net.Internal.Types
}
}
public bool IsStatic => Interop.NetMethodInfo.GetIsStatic(Handle);
public void AddParameter(string name, NetTypeInfo type)
{
Interop.NetMethodInfo.AddParameter(Handle, name, type.Handle);
@ -110,7 +115,7 @@ namespace Qml.Net.Internal.Types
IntPtr GetParameterType(IntPtr methodParameter);
[NativeSymbol(Entrypoint = "method_info_create")]
IntPtr Create(IntPtr parentTypeInfo, [MarshalAs(UnmanagedType.LPWStr), CallerFree]string methodName, IntPtr returnTypeInfo);
IntPtr Create(IntPtr parentTypeInfo, [MarshalAs(UnmanagedType.LPWStr), CallerFree]string methodName, IntPtr returnTypeInfo, bool isStatic);
[NativeSymbol(Entrypoint = "method_info_destroy")]
void Destroy(IntPtr methodInfo);
@ -118,6 +123,8 @@ namespace Qml.Net.Internal.Types
IntPtr GetMethodName(IntPtr method);
[NativeSymbol(Entrypoint = "method_info_getReturnType")]
IntPtr GetReturnType(IntPtr method);
[NativeSymbol(Entrypoint = "method_info_isStatic")]
bool GetIsStatic(IntPtr method);
[NativeSymbol(Entrypoint = "method_info_addParameter")]
void AddParameter(IntPtr method, [MarshalAs(UnmanagedType.LPWStr), CallerFree]string name, IntPtr type);