Skip to content

Commit

Permalink
Merge pull request #35 from Haacked/refactorings
Browse files Browse the repository at this point in the history
Consolidate compilation conditionals around types
  • Loading branch information
prabirshrestha committed Sep 8, 2013
2 parents 6400f06 + bfa2fb5 commit fd63918
Showing 1 changed file with 19 additions and 28 deletions.
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

0 comments on commit fd63918

Please sign in to comment.