If I have the following method;
private TSource CopyFileClientModel<TSource>(TSource fileClientOrContact)
So into this method I can pass in either a FileClient or FileContact model.
Both have a single property called Contact which is also a model as well as some other properties not common between the two.
Now I want to get that Contact model from the passed in model.
Contact sourceContact = fileClientOrContact.Contact;
However, given this is a generic, it doesn’t know that there is a Contact object within TSource.
My restriction is that I cannot place an interface against either FileClient or FileContact. I basically can’t touch either of those models.
How can I get the Contact object from TSource? Can I use reflection somehow?
You can pass along a function to return the Contact.
For example: