CSharp examples for System.Reflection:Type
Is Container Type
using System.Threading.Tasks; using System.Text; using System.Runtime.Serialization; using System.Runtime.CompilerServices; using System.Reflection.Emit; using System.Reflection; using System.Linq; using System.IO;//from w w w . j a v a 2s .c om using System.Globalization; using System.Collections.Generic; using System; public class Main{ public static bool IsContainerType(this Type t, Type containerType) { try { return (t.IsGenericType() && t.GetGenericTypeDefinition() == containerType) || t.GetInterfaces().Any(i => i.IsGenericType() && i.GetGenericTypeDefinition() == containerType); } catch (Exception) { return false; } } public static bool IsGenericType(this Type type) { var info = type.GetTypeInfo(); return info.IsGenericType; } }