How to pass / pass a parameter as a reflection? - extensibility of visual studio C #

I have an out parameter. Is it possible to convey it as a reflection? Can you give some examples of how to do this?

+4
source share
1 answer

I'm not sure if this is due to VS extensibility, but you can certainly call the method with the out parameter by reflection and find out the value of the out parameter after that:

 using System; using System.Reflection; class Test { static void Main() { MethodInfo method = typeof(int).GetMethod ("TryParse", new Type[] { typeof(string), typeof(int).MakeByRefType() }); // Second value here will be ignored, but make sure it the right type object[] args = new object[] { "10", 0 }; object result = method.Invoke(null, args); Console.WriteLine("Result: {0}", result); Console.WriteLine("args[1]: {0}", args[1]); } } 

Note that you need to keep a reference to the array used to pass arguments to the method - as after that you get the value of the out parameter. The same is true for ref .

+13
source

All Articles