开发者

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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜