I'm trying to use Type.InvokeMember(String, BindingFlags, Binder, Object, array[]) with the default binder.
one of the arguments to the target method in the object array is a reference type set to null. I want the method I'm invoking to instantiate the reference type so that I can continue using it. For example:
using System;
namespace ConsoleApplication6
{
class A
{
public void GetReferenceType(object o)
{
o = new object();
}
}
class Program
{
static void Main(string[] args)
{
object o = null;
A a = new A();
Type t = typeof(A);
t.InvokeMember("GetReferenceType", System.Reflection.BindingFlags.InvokeMethod, null, a, new object[] { o });
if (o == null)
{
throw new NullReferenceException();
}
else
{
//do something with o;
}
}
}
}
The workaround is to give A
a Property and to access o through that.
Is there another way to do it without changing A
?