开发者

How do I capture the type of Generic object in an ObservableCollection?

开发者 https://www.devze.com 2023-03-14 13:18 出处:网络
I have a method that returns an ObservableCollection on any type say ObservableCollection<Type1> ObservableCollec开发者_JAVA百科tion<Type2>

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

精彩评论

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