I’ve got an object that implements an interface, I then find that object using reflection. How can I cast the object into the interface and then place it into a List<IInterface> ?
I’ve got an object that implements an interface, I then find that object using
Share
You do not need to cast the object if it’s of a type that implements the interface.
If the type of
myObjectis justObjectthen you need to cast. I would do it this way:If
myObjectdoes not implement the given interface you end up withsubjectbeingnull. You will probably need to check for it before putting it into a list.