I have a framework that allows me to access the state and methods of objects in my project with keyboard. It relies heavily on ImpromptuInterface, which is great and fast and flexible and stuff.
For example, I invoke methods with Impromptu.InvokeMember(myObject, methodName, castParameters)
. It worked great for public and private members, but when I try to call a private member of myObject
base class, I get Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'MyType.MyMethod(Something)' is inaccessible due to its protection level
.
The simplest code that reveals the problem:
public class MainClass
{
public static void Main(string[] args)
{
var type = new PublicType();
var other = new OtherType();
Console.WriteLine(Impromptu.InvokeMember(other, "Method", 2)); //works
Console.WriteLine(Impromptu.InvokeMember(type, "Method", 2)); //crash
}
}
public class PublicType : OtherType
{}
public class OtherType
{
private bool Method(object a)
{
return a != null;
}
}
I understand why there is such a problem and I can see some possible resolutions, like looking for the class, where the method is defined and trying to cast my object to that class, but that's quite troublesome.
Is there any simple solution, preferably based strictly on Impromptu?