コード例 #1
0
        public static bool TryGetListType(this Type type, out Type nestedType)
        {
            Type genericTypeDef = null;
            Type listType       = null;

            try
            {
                genericTypeDef = type.GetGenericTypeDefinition();
            }
            catch (Exception) {}

            if (type.IsArray)
            {
                listType = type;
            }
            else if (genericTypeDef != null && GenericListTypes.Any(t => t.IsAssignableFrom(genericTypeDef)) &&
                     type.GetGenericArguments().Count() == 1)
            {
                listType = type.GetGenericArguments().Single();
            }
            else
            {
                listType = null;
            }
            nestedType = listType;
            return(listType != null);
        }
コード例 #2
0
 /// <summary>
 /// Check if the type is a generic list.
 /// </summary>
 public static bool IsGenericList(Type type)
 {
     return(GenericListTypes.Contains(type));
 }