Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GetMethod when argument comes by reference

I'm creating an instance of an object using reflection and getting the methods within the class of the object, but then the problem comes when I have to use an array of type Type to avoid ambiguity problems, here is an example of the code that I'm trying to reach.

public class BigClass
{
    public void getSomething(XmlDocument doc, ref CustomObject obj) {...}
    public void getSomething(XmlDocument doc, ref CustomObject obj, string id) {...}
}

This code comes from an external assembly (file.dll), and I'm using the next code.

Assembly a = Assembly.LoadFrom("file.dll");
Type s = a.GetType("FileNamespace.BigClass");
MethodInfo inf = s.GetMethod("getSomething", new [] {typeof(XmlDocument), typeof(CustomObject), typeof(string)});

To get the MethodInfo of the object that uses 3 arguments, but the variable "inf" comes null, I think because it doesn't find the method for the argument that uses "ref".

Is there a way to solve this?

like image 962
Chema Sarmiento Avatar asked Jul 17 '15 21:07

Chema Sarmiento


1 Answers

You'll need to look for the ref type in order to get the MethodInfo.

MethodInfo inf = s.GetMethod("getSomething", new [] {typeof(XmlDocument), typeof(CustomObject).MakeByRefType(), typeof(string)});
like image 194
evanb Avatar answered Sep 28 '22 01:09

evanb