System.Runtime.Serialization.Json.TypeMap.IsCollection C# (CSharp) Метод

IsCollection() статический приватный Метод

static private IsCollection ( Type type ) : bool
type System.Type
Результат bool
		static bool IsCollection (Type type)
		{
			if (type.GetInterface ("System.Collections.IList", false) != null)
				return true;
			if (type.GetInterface ("System.Collections.Generic.IList`1", false) != null)
				return true;
			if (type.GetInterface ("System.Collections.Generic.ICollection`1", false) != null)
				return true;
			return false;
		}

Usage Example

Пример #1
0
 internal static object CreateInstance(Type type)
 {
     if (TypeMap.IsDictionary(type))
     {
         if (type.IsGenericType)
         {
             return(Activator.CreateInstance(typeof(Dictionary <,>).MakeGenericType(type.GetGenericArguments())));
         }
         else
         {
             return(new Hashtable());
         }
     }
     else if (TypeMap.IsCollection(type))
     {
         if (type.IsGenericType)
         {
             return(Activator.CreateInstance(typeof(List <>).MakeGenericType(type.GetGenericArguments())));
         }
         else
         {
             return(new ArrayList());
         }
     }
     else
     {
         return(FormatterServices.GetUninitializedObject(type));
     }
 }
All Usage Examples Of System.Runtime.Serialization.Json.TypeMap::IsCollection