dimanche 19 avril 2020

Get list of type(s) of specific interface implemented by concrete class

Given a class, how can i find the types for the INotificationHandler<>:

public class OtherClass : INotificationHandler<Aggregate>, INotificationHandler<Quote>
{
  /* */
}

var typesList = [] { typeof(OtherClass) };

var result = MagicFunctionToGetTemplateTypesForNotificationHandlerInterface(typesList)

// where result = [] { typeof(Aggregate), typeof(Quote) };

I am considering going down the road of GetType().GenericTypeArguments[0] however want to check if there is a safer way first.

I have tried searching and appreciate this could very well be a duplicate, if so please let me know and I will delete.





Aucun commentaire:

Enregistrer un commentaire