mirror of
https://github.com/codewriter-packages/Tri-Inspector.git
synced 2025-01-22 00:08:51 -05:00
Excludes dictionary and nested collections from inspector
This commit is contained in:
parent
f40b1e4b55
commit
2350b65663
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user