Excludes dictionary and nested collections from inspector

This commit is contained in:
VladV 2023-01-09 20:24:43 +04:00
parent f40b1e4b55
commit 2350b65663

View File

@ -23,13 +23,13 @@ namespace TriInspector.Utilities
if (fieldInfo.IsPublic || fieldInfo.GetCustomAttribute<SerializeField>() != null)
{
return IsTypeSerializable(fieldInfo.FieldType);
return IsTypeSerializable(fieldInfo.FieldType, allowCollections: true);
}
return false;
}
private static bool IsTypeSerializable(Type type)
private static bool IsTypeSerializable(Type type, bool allowCollections)
{
if (type == typeof(object))
{
@ -78,13 +78,23 @@ namespace TriInspector.Utilities
if (type.IsArray)
{
var elementType = type.GetElementType();
return IsTypeSerializable(elementType);
return allowCollections && IsTypeSerializable(elementType, allowCollections: false);
}
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List<>))
if (type.IsGenericType)
{
var elementType = type.GetGenericArguments()[0];
return IsTypeSerializable(elementType);
var genericTypeDefinition = type.GetGenericTypeDefinition();
if (genericTypeDefinition == typeof(List<>))
{
var elementType = type.GetGenericArguments()[0];
return allowCollections && IsTypeSerializable(elementType, allowCollections: false);
}
if (genericTypeDefinition == typeof(Dictionary<,>))
{
return false;
}
}
if (type.GetCustomAttribute<SerializableAttribute>() != null)