Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate compilation conditionals around types #35

Merged
merged 1 commit into from
Sep 8, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 19 additions & 28 deletions src/SimpleJson/SimpleJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1560,6 +1560,18 @@ class ReflectionUtils

public delegate TValue ThreadSafeDictionaryValueFactory<TKey, TValue>(TKey key);

#if SIMPLE_JSON_TYPEINFO
public static TypeInfo GetTypeInfo(Type type)
{
return type.GetTypeInfo();
}
#else
public static Type GetTypeInfo(Type type)
{
return type;
}
#endif

public static Attribute GetAttribute(MemberInfo info, Type type)
{
#if SIMPLE_JSON_TYPEINFO
Expand Down Expand Up @@ -1598,11 +1610,7 @@ public static Type[] GetGenericTypeArguments(Type type)

public static bool IsTypeGenericeCollectionInterface(Type type)
{
#if SIMPLE_JSON_TYPEINFO
if (!type.GetTypeInfo().IsGenericType)
#else
if (!type.IsGenericType)
#endif
if (!GetTypeInfo(type).IsGenericType)
return false;

Type genericDefinition = type.GetGenericTypeDefinition();
Expand All @@ -1612,41 +1620,28 @@ public static bool IsTypeGenericeCollectionInterface(Type type)

public static bool IsAssignableFrom(Type type1, Type type2)
{
#if SIMPLE_JSON_TYPEINFO
return type1.GetTypeInfo().IsAssignableFrom(type2.GetTypeInfo());
#else
return type1.IsAssignableFrom(type2);
#endif
return GetTypeInfo(type1).IsAssignableFrom(GetTypeInfo(type2));
}

public static bool IsTypeDictionary(Type type)
{
#if SIMPLE_JSON_TYPEINFO
if (typeof(IDictionary<,>).GetTypeInfo().IsAssignableFrom(type.GetTypeInfo()))
return true;

if (!type.GetTypeInfo().IsGenericType)
return false;
#else
if (typeof(System.Collections.IDictionary).IsAssignableFrom(type))
return true;

if (!type.IsGenericType)
return false;
#endif
if (!GetTypeInfo(type).IsGenericType)
return false;

Type genericDefinition = type.GetGenericTypeDefinition();
return genericDefinition == typeof(IDictionary<,>);
}

public static bool IsNullableType(Type type)
{
return
#if SIMPLE_JSON_TYPEINFO
type.GetTypeInfo().IsGenericType
#else
type.IsGenericType
#endif
&& type.GetGenericTypeDefinition() == typeof(Nullable<>);
return GetTypeInfo(type).IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>);
}

public static object ToNullableType(object obj, Type nullableType)
Expand All @@ -1656,11 +1651,7 @@ public static object ToNullableType(object obj, Type nullableType)

public static bool IsValueType(Type type)
{
#if SIMPLE_JSON_TYPEINFO
return type.GetTypeInfo().IsValueType;
#else
return type.IsValueType;
#endif
return GetTypeInfo(type).IsValueType;
}

public static IEnumerable<ConstructorInfo> GetConstructors(Type type)
Expand Down