Invoking a method via reflection with generics and overrides

前端 未结 2 1976
孤城傲影
孤城傲影 2021-01-18 08:40

I\'m trying to invoke the RegisterType method in the Unity container. RegisterType has a total of 16 overrides (some of those are parameters some are types).

I\'m tr

2条回答
  •  伪装坚强ぢ
    2021-01-18 09:31

    My initial post mentioned that I had tried passing null as a 3rd parameter and that the app "croaked." Specifically, it was getting a null reference exception and I should have been more clear about that.

    The solution was to pass "new InjectionMember[0]" instead of null, so the Invoke() should have looked like this:

    registerTypeSpecific.Invoke(Container, new object[] { "MockData", new ContainerControlledLifetimeManager(), new InjectionMember[0] }); 
    

    Thanks to Jason for his help. His sample sent me down the path that eventually led to the answer.

提交回复
热议问题