Skip to content

Commit

Permalink
Fixes for .NET core
Browse files Browse the repository at this point in the history
  • Loading branch information
BrknRobot authored and jacobdufault committed May 13, 2017
1 parent cb313ab commit c01db30
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace FullSerializer.Internal.Converters {
// expected.
public class UnityEvent_Converter : fsConverter {
public override bool CanProcess(Type type) {
return typeof(UnityEvent).Resolve().IsAssignableFrom(type) && type.IsGenericType == false;
return typeof(UnityEvent).Resolve().IsAssignableFrom(type.Resolve()) && type.IsGenericType() == false;
}

public override bool RequestCycleSupport(Type storageType) {
Expand Down
11 changes: 6 additions & 5 deletions Assets/FullSerializer/Source/Internal/fsPortableReflection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;

#if USE_TYPEINFO
namespace System {
Expand All @@ -25,9 +26,9 @@ public static Type[] GetTypes(this Assembly assembly) {

public static Type GetType(this Assembly assembly, string name, bool throwOnError) {
var types = assembly.GetTypes();
for (int i = 0; i < types.Length; ++i) {
if (types[i].Name == name) {
return types[i];
foreach (var type in types) {
if (type.Name == name) {
return type.GetType();
}
}

Expand Down Expand Up @@ -109,8 +110,8 @@ public static Attribute GetAttribute(MemberInfo element, Type attributeType, boo
Attribute attribute;
if (_cachedAttributeQueries.TryGetValue(query, out attribute) == false) {
var attributes = element.GetCustomAttributes(attributeType, /*inherit:*/ true);
if (attributes.Length > 0)
attribute = (Attribute)attributes[0];
if (attributes.Any())
attribute = (Attribute)attributes.First();
if (shouldCache)
_cachedAttributeQueries[query] = attribute;
}
Expand Down
27 changes: 27 additions & 0 deletions Assets/FullSerializer/Source/Internal/fsTypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,32 @@ public static string CSharpName(this Type type, bool includeNamespace) {

return name;
}

public static bool IsInterface(this Type type)
{
#if NETFX_CORE
return type.GetTypeInfo().IsInterface;
#else
return type.IsInterface;
#endif
}

public static bool IsAbstract(this Type type)
{
#if NETFX_CORE
return type.GetTypeInfo().IsAbstract;
#else
return type.IsAbstract;
#endif
}

public static bool IsGenericType(this Type type)
{
#if NETFX_CORE
return type.GetTypeInfo().IsGenericType;
#else
return type.IsGenericType;
#endif
}
}
}
2 changes: 1 addition & 1 deletion Assets/FullSerializer/Source/Reflection/fsTypeCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private static bool TryIndirectTypeLookup(string typeName, out Type type) {
// every type's full name
foreach (var foundType in assembly.GetTypes()) {
if (foundType.FullName == typeName) {
type = foundType;
type = foundType.GetType();
return true;
}
}
Expand Down
6 changes: 3 additions & 3 deletions Assets/FullSerializer/Source/fsSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,10 @@ public void Clear() {
private readonly Dictionary<Type, Type> _abstractTypeRemap;

private void RemapAbstractStorageTypeToDefaultType(ref Type storageType) {
if ((storageType.IsInterface || storageType.IsAbstract) == false)
if ((storageType.IsInterface() || storageType.IsAbstract()) == false)
return;

if (storageType.IsGenericType) {
if (storageType.IsGenericType()) {
Type remappedGenericType;
if (_abstractTypeRemap.TryGetValue(storageType.GetGenericTypeDefinition(), out remappedGenericType)) {
Type[] genericArguments = storageType.GetGenericArguments();
Expand Down Expand Up @@ -406,7 +406,7 @@ public void RemoveProcessor<TProcessor>() {
/// IList{T} => List{T} or IDictionary{TKey, TValue} => Dictionary{TKey, TValue}.
/// </summary>
public void SetDefaultStorageType(Type abstractType, Type defaultStorageType) {
if ((abstractType.IsInterface || abstractType.IsAbstract) == false)
if ((abstractType.IsInterface() || abstractType.IsAbstract()) == false)
throw new ArgumentException("|abstractType| must be an interface or abstract type");
_abstractTypeRemap[abstractType] = defaultStorageType;
}
Expand Down

0 comments on commit c01db30

Please sign in to comment.