-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathHelpers.cs
More file actions
39 lines (35 loc) · 1.21 KB
/
Helpers.cs
File metadata and controls
39 lines (35 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Collections;
using System.Collections.Generic;
using SharpDX;
namespace DevTree
{
public partial class DevPlugin
{
private static readonly HashSet<Type> PrimitiveTypes = new HashSet<Type>
{
typeof(Enum),
typeof(string),
typeof(decimal),
typeof(DateTime),
typeof(TimeSpan),
typeof(Guid),
typeof(Vector2),
typeof(Vector3)
};
public static bool IsEnumerable(Type type)
{
return typeof(IEnumerable).IsAssignableFrom(type) || typeof(IEnumerable<>).IsAssignableFrom(type);
}
public static bool IsCollection(Type type)
{
return typeof(ICollection).IsAssignableFrom(type) || typeof(ICollection<>).IsAssignableFrom(type);
}
public static bool IsSimpleType(Type type)
{
return type.IsPrimitive || PrimitiveTypes.Contains(type) || Convert.GetTypeCode(type) != TypeCode.Object ||
type.BaseType == typeof(Enum) || type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) &&
IsSimpleType(type.GetGenericArguments()[0]);
}
}
}