// Copyright © 2016 The CefSharp Authors. All rights reserved. // // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. using System; using System.Collections.Generic; using System.Linq; using System.Reflection; namespace CefSharp.ModelBinding { /// /// Containing extensions for the object. /// internal static class ModelBindingExtensions { /// /// Checks if a type is an array or not /// /// The type to check. /// if the type is an array, otherwise . public static bool IsArray(this Type source) { return source.GetTypeInfo().BaseType == typeof(Array); } /// /// Checks if a type is an collection or not /// /// The type to check. /// if the type is a collection, otherwise . public static bool IsCollection(this Type source) { var collectionType = typeof(ICollection<>); return source.GetTypeInfo().IsGenericType && source .GetInterfaces() .Any(i => i.GetTypeInfo().IsGenericType && i.GetGenericTypeDefinition() == collectionType); } /// /// Checks if a type is enumerable or not /// /// The type to check. /// if the type is an enumerable, otherwise . public static bool IsEnumerable(this Type source) { var enumerableType = typeof(IEnumerable<>); return source.GetTypeInfo().IsGenericType && source.GetGenericTypeDefinition() == enumerableType; } } }