bring in useful InvokeMethod functionality from MBS.Framework.UI

This commit is contained in:
Michael Becker 2022-03-14 21:03:17 -04:00
parent f3f9cf47f2
commit 2da999008c
No known key found for this signature in database
GPG Key ID: DA394832305DA332

View File

@ -24,7 +24,7 @@ using System.Reflection;
namespace MBS.Framework
{
public class Reflection
public static class Reflection
{
public class ManifestResourceStream
{
@ -168,10 +168,10 @@ namespace MBS.Framework
catch (ReflectionTypeLoadException ex)
{
Console.Error.WriteLine("ReflectionTypeLoadException(" + ex.LoaderExceptions.Length.ToString() + "): " + asm.FullName);
for (int i = 0; i < ex.LoaderExceptions.Length; i++)
for (int i = 0; i < ex.LoaderExceptions.Length; i++)
{
Console.Error.WriteLine("\t" + ex.LoaderExceptions[i].Message);
Console.Error.WriteLine();
Console.Error.WriteLine("\t" + ex.LoaderExceptions[i].Message);
Console.Error.WriteLine();
}
types1 = ex.Types;
@ -272,5 +272,44 @@ namespace MBS.Framework
return default(T);
}
public static void InvokeMethod(object obj, string meth, params object[] parms)
{
if (obj == null)
{
Console.WriteLine("Engine::InvokeMethod: obj is null");
return;
}
Type t = obj.GetType();
System.Reflection.MethodInfo mi = t.GetMethod(meth, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
if (mi != null)
{
mi.Invoke(obj, parms);
}
else
{
Console.WriteLine("Engine::InvokeMethod: method not found '" + meth + "' on '" + t.FullName + "'");
}
}
public static void InvokeMethod(Type type, string meth, params object[] parms)
{
if (type == null)
{
Console.WriteLine("Engine::InvokeMethod: obj is null");
return;
}
Type t = type;
System.Reflection.MethodInfo mi = t.GetMethod(meth, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
if (mi != null)
{
mi.Invoke(null, parms);
}
else
{
Console.WriteLine("Engine::InvokeMethod: static method not found '" + meth + "' on '" + t.FullName + "'");
}
}
}
}