Fix SerializeReference on non serializable collections (#167)

This commit is contained in:
Saeed Barari 2024-07-18 23:43:05 +03:30 committed by GitHub
parent 6c844f0b69
commit f2a652a75f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -27,7 +27,27 @@ namespace TriInspector.Utilities
if (fieldInfo.GetCustomAttribute<SerializeReference>() != null) if (fieldInfo.GetCustomAttribute<SerializeReference>() != null)
{ {
// if it's a list or array, the base type should be serializable
if (fieldInfo.FieldType.IsArray)
{
var type = fieldInfo.FieldType.GetElementType();
if (type.IsSerializable || type.IsInterface)
return true; return true;
else
return false;
}
else if (fieldInfo.FieldType.IsGenericType && fieldInfo.FieldType.GetGenericTypeDefinition() == typeof(List<>))
{
var type = fieldInfo.FieldType.GenericTypeArguments[0];
if (type.IsSerializable || type.IsInterface)
return true;
else
return false;
}
else
{
return true;
}
} }
if (fieldInfo.IsPublic || fieldInfo.GetCustomAttribute<SerializeField>() != null) if (fieldInfo.IsPublic || fieldInfo.GetCustomAttribute<SerializeField>() != null)