mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-16 22:27:45 +08:00
Add support for methods with ref/in/out args
This commit is contained in:
parent
129a7e3765
commit
c39e097378
@ -114,8 +114,9 @@ namespace Explorer
|
|||||||
var pi = memberInfo as PropertyInfo;
|
var pi = memberInfo as PropertyInfo;
|
||||||
var mi = memberInfo as MethodInfo;
|
var mi = memberInfo as MethodInfo;
|
||||||
|
|
||||||
// if PropertyInfo, check if can process args
|
// Check if can process args
|
||||||
if (pi != null && !CanProcessArgs(pi.GetIndexParameters()))
|
if ((pi != null && !CanProcessArgs(pi.GetIndexParameters()))
|
||||||
|
|| (mi != null && !CanProcessArgs(mi.GetParameters())))
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -127,14 +128,7 @@ namespace Explorer
|
|||||||
|
|
||||||
if (mi != null)
|
if (mi != null)
|
||||||
{
|
{
|
||||||
if (CacheMethod.CanEvaluate(mi))
|
holder = new CacheMethod();
|
||||||
{
|
|
||||||
holder = new CacheMethod();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (valueType == typeof(GameObject) || valueType == typeof(Transform))
|
else if (valueType == typeof(GameObject) || valueType == typeof(Transform))
|
||||||
{
|
{
|
||||||
@ -211,7 +205,18 @@ namespace Explorer
|
|||||||
{
|
{
|
||||||
foreach (var param in parameters)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
@ -241,6 +246,11 @@ namespace Explorer
|
|||||||
var input = m_argumentInput[i];
|
var input = m_argumentInput[i];
|
||||||
var type = m_arguments[i].ParameterType;
|
var type = m_arguments[i].ParameterType;
|
||||||
|
|
||||||
|
if (type.IsByRef)
|
||||||
|
{
|
||||||
|
type = type.GetElementType();
|
||||||
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(input))
|
if (!string.IsNullOrEmpty(input))
|
||||||
{
|
{
|
||||||
// strings can obviously just be used directly
|
// strings can obviously just be used directly
|
||||||
|
@ -18,12 +18,6 @@ namespace Explorer
|
|||||||
|
|
||||||
public string[] GenericArgInput = new string[0];
|
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()
|
public override void Init()
|
||||||
{
|
{
|
||||||
var mi = (MemInfo as MethodInfo);
|
var mi = (MemInfo as MethodInfo);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Explorer.Tests
|
namespace Explorer.Tests
|
||||||
@ -21,10 +22,16 @@ namespace Explorer.Tests
|
|||||||
public static int StaticField = 5;
|
public static int StaticField = 5;
|
||||||
public int NonStaticField;
|
public int NonStaticField;
|
||||||
|
|
||||||
// test a generic method
|
|
||||||
public static string TestGeneric<C, T>(string arg0) where C : Component
|
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.
|
//// this type of generic is not supported, due to requiring a non-primitive argument.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user