vendredi 15 mai 2015

How can I determine which class called a public method on an interface?

I am working on a project that relies heavily on NServiceBus. Unfortunately it has gotten a bit messy, and even though it is written in C#, there is some chaos to it. For example I have Bus.Publish(A) somewhere, then elsewhere is public AHandler : IHandleMessages<A> which may be fine but since this is a P/S pattern there are often multiple handlers. There is some intrinsic need to memorize the project and it is difficult for new developers to follow the flow of code.

My solution to this was to create a console app, or perhaps some sort of UI, that would use reflection to scan the assembly and draw a map of my project for me. So far I've been able to effectively pick up all of the public class _Handler : IHandleMessages<_> which is great, but now I need to determine where the messages are originating from.

In particular, I am wondering if there is a way using reflection to determine within which classes Bus.Publish(_) is being called (Bus is actually an instance of IBus). For isntance if public void Handler(A a) { Bus.Publish(B) } I want to know the argument passed into Bus.Publish() (so B) and also the name of the class that contains this handler.





Aucun commentaire:

Enregistrer un commentaire