Private Accessor generic method

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

    Posted 06 Aug 2015 Link to this post

    I have a private Generic method and I want to call it using Private Accessor, How can i do that.

    private void PopulateCollection<T>(List<IDataItem> fromCollection, ObservableCollection<T> toCollection){}




  2. Answer
    Stefan avatar
    198 posts

    Posted 11 Aug 2015 Link to this post

    Hello Vikas,

    You need to identify the method using reflection:
    var inst = new PrivateAccessor(new MyType());
    var method = typeof(MyType)
        .GetMethod("PopulateCollection", BindingFlags.NonPublic | BindingFlags.Instance)
    inst.CallMethod(method, fromCollection, toCollection);

    PrivateAccessor should be made easier to use with generic methods, so I added a feature suggestion to our backlog.

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. DevCraft R3 2016 release webinar banner
Back to Top