How do I capture the type of Generic object in an ObservableCollection?
I have a method that returns an ObservableCollection on any type say
ObservableCollection<Type1>
ObservableCollec开发者_JAVA百科tion<Type2>
ObservableCollection<Type3>
i want to be able to capture the Type (Type1, Type2, Type3) of that at run-time when that how do i do it?
what i mean at run time is the objects returned are different at runtime and i should be able to catpure the Type and execute an approprate function ( using switch case )
use GetGenericArguments to get array of types
ObservableCollection<Type1> sample = new ObservableCollection<Type1>();
var types = sample.GetType().GetGenericArguments();
精彩评论