c# - Type.InvokeMember and reference types -


I'm trying to use [] with default binder.

The target method in the object array is a set of empty types that is set to be blank. I want the method that I am applying to instantize the reference type so that I can continue to use it. For example:

  using the system; Namespace Console Application 6 {Class A {Public Zero GetReferenceType (Object O) {O = New Object (); }} Class program {static zero main (string [] args) {object o = null; AA = new A (); Type T = Typef (A); T.InvokeMember ("GetReferenceType", System. Reflection.BindingFlags.InvokeMethod, Zero, One, New Object [] {o}); If (o == empty) {new tap reference expression (); } Do something else with o / o; }}}}  

The solution is to give A a property and use oo through it.

Is there any other way to do this a

Without changing, OK, you have to make two changes here:

  • GetReferenceType your ref :

    You do to do this because your method is currently in the external world. No you should read me

  • Instead of the original context, use the value within the array after InvokeMember :

      A = New A (); Type T = Typef (A); Object [] args = new object [] {null}; T.InvokeMember ("GetReferenceType", BindingFlags.InvokeMethod, Blank, A, Args); Object o = args [0];  

When you create an array, for example new object [] {o} with the Value of o - it does not associate that array element with o variable

A better solution will be to create a new value GetReferenceType return , though ... it is rarely zero There is a good idea to use the outside or riff parameter in the method.


Comments