2

I have a method that returns an ObservableCollection on any type say

ObservableCollection<Type1>
ObservableCollection<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 )

  • 1
    what do you mean with "capture the type at runtime"? – Daniel Hilgarth Jun 21 '11 at 08:13
  • I suggest you edit the original question to answer Daniel's comment. Stecya's answer seems right, but the question is still ambiguous. Could you add a code sample showing what your function's return type is, and what type of data/variable you're trying to get from it? – Merlyn Morgan-Graham Jun 21 '11 at 08:17
  • @Daniel @Merlyn 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 :) ) Stecya solved my problem :) –  Jun 21 '11 at 08:21

1 Answers1

2

use GetGenericArguments to get array of types

    ObservableCollection<Type1> sample = new ObservableCollection<Type1>();
    var types = sample.GetType().GetGenericArguments();
Stecya
  • 22,896
  • 10
  • 72
  • 102