chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
Hi, I try to invoke a private method with ref parameter. However, I got exception saying cannot find the one with signature UpdateDictionary(Dictionary), and suggest me try UpdateDictionary(&Dictionary). How can I solve this problem?

class Helper{
       private Doc UpdateDictionary(ref Dictionary dic)
     {
              ...
     }
}
Isolate.Invoke.Method(typeof(Helper), "UpdateDictionary", new object[] {dic});
asked by XChen29 (2.7k points)

3 Answers

0 votes
Hi XChen,

Invoking a private method with refout parameters is a missing feature.
It is in our backlog and will be included in the future.
answered by alex (18k points)
0 votes
Hi,

Is this feature available now in the latest version? I am still having the same problem. Is there a workaround for this?
answered by abhip (140 points)
0 votes
Hi,

You can use reflection to invoke private method with ref params:

[TestClass]
public class UnitTest1
{
    [TestMethod]
    public void TestMethod1()
    {

        var foo = new Foo();

        var method = typeof(Foo).GetMethod("Bar", BindingFlags.NonPublic | BindingFlags.Instance,  null,
              new[] { typeof(int),
                      typeof(double).MakeByRefType(),
                      typeof(double).MakeByRefType()},
              null);

        var parameters = new object[] {0,0.0,0.0};
        var ret = (int) method.Invoke(foo, parameters);

        Assert.AreEqual(0, parameters[0]);
        Assert.AreEqual(1.0, parameters[1]);
        Assert.AreEqual(2.0, parameters[2]);          
        Assert.AreEqual(3, ret);          
    }
}

public class Foo
{
    private int Bar(int a, ref double b, out double c)
    {
        b = 1;
        c = 2;
        return 3;
    }
}
answered by alex (18k points)
...