MakeMethodAccessible and MakeFieldAccessible now are recursive, so they include private members in inherit members
This commit is contained in:
@@ -110,6 +110,18 @@ namespace Barotrauma
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static FieldInfo FindFieldRecursively(Type type, string fieldName)
|
||||||
|
{
|
||||||
|
var field = type.GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
|
||||||
|
|
||||||
|
if (field == null && type.BaseType != null)
|
||||||
|
{
|
||||||
|
return FindFieldRecursively(type.BaseType, fieldName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return field;
|
||||||
|
}
|
||||||
|
|
||||||
public static void MakeFieldAccessible(IUserDataDescriptor IUUD, string fieldName)
|
public static void MakeFieldAccessible(IUserDataDescriptor IUUD, string fieldName)
|
||||||
{
|
{
|
||||||
if (IUUD == null)
|
if (IUUD == null)
|
||||||
@@ -121,6 +133,11 @@ namespace Barotrauma
|
|||||||
var descriptor = (StandardUserDataDescriptor)IUUD;
|
var descriptor = (StandardUserDataDescriptor)IUUD;
|
||||||
var field = IUUD.Type.GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
|
var field = IUUD.Type.GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
|
||||||
|
|
||||||
|
if (field == null)
|
||||||
|
{
|
||||||
|
field = FindFieldRecursively(IUUD.Type, fieldName);
|
||||||
|
}
|
||||||
|
|
||||||
if (field == null)
|
if (field == null)
|
||||||
{
|
{
|
||||||
GameMain.Lua.HandleLuaException(new Exception($"Tried to make field '{fieldName}' accessible, but the field doesn't exist."));
|
GameMain.Lua.HandleLuaException(new Exception($"Tried to make field '{fieldName}' accessible, but the field doesn't exist."));
|
||||||
@@ -131,6 +148,18 @@ namespace Barotrauma
|
|||||||
descriptor.AddMember(fieldName, new FieldMemberDescriptor(field, InteropAccessMode.Default));
|
descriptor.AddMember(fieldName, new FieldMemberDescriptor(field, InteropAccessMode.Default));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static MethodInfo FindMethodRecursively(Type type, string methodName)
|
||||||
|
{
|
||||||
|
var method = type.GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
|
||||||
|
|
||||||
|
if (method == null && type.BaseType != null)
|
||||||
|
{
|
||||||
|
return FindMethodRecursively(type.BaseType, methodName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return method;
|
||||||
|
}
|
||||||
|
|
||||||
public static void MakeMethodAccessible(IUserDataDescriptor IUUD, string methodName)
|
public static void MakeMethodAccessible(IUserDataDescriptor IUUD, string methodName)
|
||||||
{
|
{
|
||||||
if (IUUD == null)
|
if (IUUD == null)
|
||||||
@@ -144,7 +173,12 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (method == null)
|
if (method == null)
|
||||||
{
|
{
|
||||||
GameMain.Lua.HandleLuaException(new Exception($"Tried to make method '{method}' accessible, but the method doesn't exist."));
|
method = FindMethodRecursively(IUUD.Type, methodName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (method == null)
|
||||||
|
{
|
||||||
|
GameMain.Lua.HandleLuaException(new Exception($"Tried to make method '{methodName}' accessible, but the method doesn't exist."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user