Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/aspnetwebstack.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/System.Web.Http.OData/TypeHelper.cs')
-rw-r--r--src/System.Web.Http.OData/TypeHelper.cs47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/System.Web.Http.OData/TypeHelper.cs b/src/System.Web.Http.OData/TypeHelper.cs
index f0fbd277..deed93c2 100644
--- a/src/System.Web.Http.OData/TypeHelper.cs
+++ b/src/System.Web.Http.OData/TypeHelper.cs
@@ -13,6 +13,53 @@ namespace System.Web.Http
{
internal static class TypeHelper
{
+ // Gets the collection element type.
+ public static Type GetInnerElementType(this Type type)
+ {
+ Type elementType;
+ type.IsCollection(out elementType);
+ Contract.Assert(elementType != null);
+
+ return elementType;
+ }
+
+ public static bool IsCollection(this Type type)
+ {
+ Type elementType;
+ return type.IsCollection(out elementType);
+ }
+
+ public static bool IsCollection(this Type type, out Type elementType)
+ {
+ if (type == null)
+ {
+ throw Error.ArgumentNull("type");
+ }
+
+ elementType = type;
+
+ // see if this type should be ignored.
+ if (type == typeof(string))
+ {
+ return false;
+ }
+
+ Type collectionInterface
+ = type.GetInterfaces()
+ .Union(new[] { type })
+ .FirstOrDefault(
+ t => t.IsGenericType
+ && t.GetGenericTypeDefinition() == typeof(IEnumerable<>));
+
+ if (collectionInterface != null)
+ {
+ elementType = collectionInterface.GetGenericArguments().Single();
+ return true;
+ }
+
+ return false;
+ }
+
/// <summary>
/// Determines whether the given type is a primitive type or
/// is a <see cref="string"/>, <see cref="DateTime"/>, <see cref="Decimal"/>,