Add support for methods with ref/in/out args

This commit is contained in:
sinaioutlander 2020-09-19 00:14:04 +10:00
parent 129a7e3765
commit c39e097378
3 changed files with 30 additions and 19 deletions

View File

@ -114,8 +114,9 @@ namespace Explorer
var pi = memberInfo as PropertyInfo;
var mi = memberInfo as MethodInfo;
// if PropertyInfo, check if can process args
if (pi != null && !CanProcessArgs(pi.GetIndexParameters()))
// Check if can process args
if ((pi != null && !CanProcessArgs(pi.GetIndexParameters()))
|| (mi != null && !CanProcessArgs(mi.GetParameters())))
{
return null;
}
@ -127,14 +128,7 @@ namespace Explorer
if (mi != null)
{
if (CacheMethod.CanEvaluate(mi))
{
holder = new CacheMethod();
}
else
{
return null;
}
holder = new CacheMethod();
}
else if (valueType == typeof(GameObject) || valueType == typeof(Transform))
{
@ -211,7 +205,18 @@ namespace Explorer
{
foreach (var param in parameters)
{
if (!param.ParameterType.IsPrimitive && param.ParameterType != typeof(string))
var pType = param.ParameterType;
if (pType.IsByRef && pType.HasElementType)
{
pType = pType.GetElementType();
}
if (pType.IsPrimitive || pType == typeof(string))
{
continue;
}
else
{
return false;
}
@ -241,6 +246,11 @@ namespace Explorer
var input = m_argumentInput[i];
var type = m_arguments[i].ParameterType;
if (type.IsByRef)
{
type = type.GetElementType();
}
if (!string.IsNullOrEmpty(input))
{
// strings can obviously just be used directly

View File

@ -18,12 +18,6 @@ namespace Explorer
public string[] GenericArgInput = new string[0];
public static bool CanEvaluate(MethodInfo mi)
{
// primitive and string args supported
return CanProcessArgs(mi.GetParameters());
}
public override void Init()
{
var mi = (MemInfo as MethodInfo);

View File

@ -1,5 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using System;
using UnityEngine;
namespace Explorer.Tests
@ -21,10 +22,16 @@ namespace Explorer.Tests
public static int StaticField = 5;
public int NonStaticField;
// test a generic method
public static string TestGeneric<C, T>(string arg0) where C : Component
{
return "C: " + typeof(C).FullName + ", T: " + typeof(T).FullName + ", arg0: " + arg0;
return $"C: '{typeof(C).FullName}', T: '{typeof(T).FullName}', arg0: '{arg0}'";
}
public static string TestRefInOutGeneric<T>(ref string arg0, in int arg1, out string arg2)
{
arg2 = "this is arg2";
return $"T: '{typeof(T).FullName}', ref arg0: '{arg0}', in arg1: '{arg1}', out arg2: '{arg2}'";
}
//// this type of generic is not supported, due to requiring a non-primitive argument.