I have a function which takes a generic:
public static ShowTrackChangesViewModel CreateVM<T>(IList<TrackChanges> TrackChanges, T entity)
{
//How do i access T properties ?
}
T here is an entityFramework object. How do i cast it back to the real one to access its property ?
Do i need to write a big if code ?
Thx
You can add this little gem to say that
Tshould be an object of typeMyBaseType:Then, you can use
entityas if it were a MyBaseType. If you need specific properties that aren’t in a base class, then you don’t want a generic method (because it wouldn’t be generic!).Hope that helps!