mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-04 19:25:01 +00:00
0d48e30418
Remove IsCollectionOrArray extension method, use the long hand - makes the code more readable. Switch to using Activator.CreateInstance directly Remove a large number of unused extensions in ModelBindingExtensions Alternate to #2052
54 lines
2.0 KiB
C#
54 lines
2.0 KiB
C#
// Copyright © 2010-2017 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
|
|
{
|
|
/// <summary>
|
|
/// Containing extensions for the <see cref="Type"/> object.
|
|
/// </summary>
|
|
internal static class ModelBindingExtensions
|
|
{
|
|
/// <summary>
|
|
/// Checks if a type is an array or not
|
|
/// </summary>
|
|
/// <param name="source">The type to check.</param>
|
|
/// <returns><see langword="true" /> if the type is an array, otherwise <see langword="false" />.</returns>
|
|
public static bool IsArray(this Type source)
|
|
{
|
|
return source.GetTypeInfo().BaseType == typeof(Array);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks if a type is an collection or not
|
|
/// </summary>
|
|
/// <param name="source">The type to check.</param>
|
|
/// <returns><see langword="true" /> if the type is a collection, otherwise <see langword="false" />.</returns>
|
|
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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks if a type is enumerable or not
|
|
/// </summary>
|
|
/// <param name="source">The type to check.</param>
|
|
/// <returns><see langword="true" /> if the type is an enumerable, otherwise <see langword="false" />.</returns>
|
|
public static bool IsEnumerable(this Type source)
|
|
{
|
|
var enumerableType = typeof(IEnumerable<>);
|
|
|
|
return source.GetTypeInfo().IsGenericType && source.GetGenericTypeDefinition() == enumerableType;
|
|
}
|
|
}
|
|
}
|