Files
Terminal.Gui/UnitTests/ReflectionTools.cs
BDisp 75c0160d96 Fixes #1999. Prevents the mouseGrabView being executed with a null view. (#2000)
* Unit test that will fail without the fix.

* ScrollView must return true after ungrab the mouse to allow the View property run after returned.

* Fixes #1999. Prevents the mouseGrabView being executed with a null view.

* Added one more assert null check.
2022-09-14 18:18:00 -07:00

36 lines
991 B
C#

using System;
using System.Reflection;
public static class ReflectionTools {
// If the class is non-static
public static Object InvokePrivate (Object objectUnderTest, string method, params object [] args)
{
Type t = objectUnderTest.GetType ();
return t.InvokeMember (method,
BindingFlags.InvokeMethod |
BindingFlags.NonPublic |
BindingFlags.Instance |
BindingFlags.Static,
null,
objectUnderTest,
args);
}
// if the class is static
public static Object InvokePrivate (Type typeOfObjectUnderTest, string method, params object [] args)
{
MemberInfo [] members = typeOfObjectUnderTest.GetMembers (BindingFlags.NonPublic | BindingFlags.Static);
foreach (var member in members) {
if (member.Name == method) {
return typeOfObjectUnderTest.InvokeMember (method,
BindingFlags.NonPublic |
BindingFlags.Static |
BindingFlags.InvokeMethod,
null,
typeOfObjectUnderTest,
args);
}
}
return null;
}
}