While trying to make my plugin compatible with WSA I've found some errors in the (brilliant!) fsPortableReflection class and missing Resolve calls elsewhere in FS.
First, in fsPortableReflection, using Linq is missing when USE_TYPEINFO is enabled. I suspect this is due to the using directive not having been wrapper in a preprocessor conditional and therefore getting removed by a Remove and sort usings command.
The usings should read:
using System;
using System.Collections.Generic;
using System.Reflection;
#if USE_TYPEINFO
using System.Linq;
#endif
The method fsSerializer.RemapAbstractStorageTypeToDefaultType is missing the required Resolve calls. Here's my implementation of them:
private void RemapAbstractStorageTypeToDefaultType(ref Type storageType) {
if ((storageType.Resolve().IsInterface || storageType.Resolve().IsAbstract) == false)
return;
if (storageType.Resolve().IsGenericType) {
Type remappedGenericType;
if (_abstractTypeRemap.TryGetValue(storageType.Resolve().GetGenericTypeDefinition(), out remappedGenericType)) {
Type[] genericArguments = storageType.GetGenericArguments();
storageType = remappedGenericType.Resolve().MakeGenericType(genericArguments);
}
}
else {
Type remappedType;
if (_abstractTypeRemap.TryGetValue(storageType, out remappedType))
storageType = remappedType;
}
}
The method fsSerializer.SetDefaultStorageType is also missing the Resolve calls:
public void SetDefaultStorageType(Type abstractType, Type defaultStorageType) {
if ((abstractType.Resolve().IsInterface || abstractType.Resolve().IsAbstract) == false)
throw new ArgumentException("|abstractType| must be an interface or abstract type");
_abstractTypeRemap[abstractType] = defaultStorageType;
}
The method UnityEvent_Converter.CanProcess is also missing Resolve calls:
And finally, for a reason that completely eludes me (can't find the documentation for it anywhere), in fsProtableReflection.GetAttribute(MemberInfo, Type, bool), MemberInfo.GetCustomAttributes seems to return an IEnumerable<Attribute> instead of an object[] on WSA platforms, therefore making the length and index call throw errors. My temporary fix is simply to force it into an array:
var attributes = element.GetCustomAttributes(attributeType, /*inherit:*/ true).ToArray();
I realize now that this last fix moves the System.Linq dependency out of the preprocessor conditional I mentioned earlier.
While trying to make my plugin compatible with WSA I've found some errors in the (brilliant!) fsPortableReflection class and missing Resolve calls elsewhere in FS.
First, in fsPortableReflection,
using Linq
is missing whenUSE_TYPEINFO
is enabled. I suspect this is due to the using directive not having been wrapper in a preprocessor conditional and therefore getting removed by aRemove and sort usings
command.The usings should read:
The method
fsSerializer.RemapAbstractStorageTypeToDefaultType
is missing the requiredResolve
calls. Here's my implementation of them:The method
fsSerializer.SetDefaultStorageType
is also missing theResolve
calls:public void SetDefaultStorageType(Type abstractType, Type defaultStorageType) { if ((abstractType.Resolve().IsInterface || abstractType.Resolve().IsAbstract) == false) throw new ArgumentException("|abstractType| must be an interface or abstract type"); _abstractTypeRemap[abstractType] = defaultStorageType; }
The method
UnityEvent_Converter.CanProcess
is also missingResolve
calls:And finally, for a reason that completely eludes me (can't find the documentation for it anywhere), in
fsProtableReflection.GetAttribute(MemberInfo, Type, bool)
,MemberInfo.GetCustomAttributes
seems to return anIEnumerable<Attribute>
instead of anobject[]
on WSA platforms, therefore making the length and index call throw errors. My temporary fix is simply to force it into an array:I realize now that this last fix moves the
System.Linq
dependency out of the preprocessor conditional I mentioned earlier.