Mega Code Archive

 
Categories / C# Book / 09 Reflection
 

0626 Generic Type Members

You can obtain member metadata for both unbound and closed generic types: using System; using System.Reflection; using System.Collections.Generic; class Program { static void Main() { PropertyInfo unbound = typeof(IEnumerator<>).GetProperty("Current"); PropertyInfo closed = typeof(IEnumerator<int>).GetProperty("Current"); Console.WriteLine(unbound); // T Current Console.WriteLine(closed); // Int32 Current Console.WriteLine(unbound.PropertyType.IsGenericParameter); // True Console.WriteLine(closed.PropertyType.IsGenericParameter); // False } } The output: T Current Int32 Current True False