This is a migrated thread and some comments may be shown as answers.

Call Private method with ref parameters

1 Answer 231 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Vikas
Top achievements
Rank 1
Vikas asked on 24 Nov 2014, 07:48 PM
I am using CallMethod to call a private method and it works great, but I need to call a method that has some ref parameters, Is it possible to do that
Also i would like to compare the values in the ref after the method execution finishes, basically instead of returning one value method is manipulating multiple values and i need to Assert all of them

Thanks
vikas

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 27 Nov 2014, 12:10 PM
Hello Vikas,

Here's how you can do it:
public class HasRef
{
    private void Do(ref int a)
    {
        a = a * 2;
    }
}
 
[TestMethod, TestCategory("Elevated"), TestCategory("NonPublic")]
public void PrivateAccessor_RefCall()
{
    var inst = new PrivateAccessor(new HasRef());
    var args = new object[] { 20 };
    inst.CallMethod("Do", args);
    Assert.AreEqual(40, args[0]);
}

Ref and out arguments are passed back into the array of arguments passed to CallMethod.

Regards,
Stefan
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
General Discussions
Asked by
Vikas
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or