Call Private method with ref parameters

2 posts, 0 answers
  1. Vikas
    Vikas avatar
    64 posts
    Member since:
    May 2014

    Posted 24 Nov 2014 Link to this post

    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

  2. Stefan
    Stefan avatar
    198 posts

    Posted 27 Nov 2014 Link to this post

    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.


    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.

  3. DevCraft R3 2016 release webinar banner
Back to Top