samedi 18 mars 2017

How to use Reflection to call a method of type "private async Task"

I have a class called PageProcessor with a method

    private static async Task InsertPosts(IEnumerable<LrcPost> posts)
    {
       // ...
    }

and I'm trying to call it in one of my unit tests like

        PageProcessor processor = new PageProcessor();
        MethodInfo dynMethod = processor.GetType()
            .GetMethod
            (
                "InsertPosts",
                BindingFlags.NonPublic | BindingFlags.Instance
            );
       dynMethod.Invoke(processor, new object[] { posts });

but am getting an NRE. Any idea why?





Aucun commentaire:

Enregistrer un commentaire