Skip to content

Commit

Permalink
CompositeSerializationBinder - fixing a backward compatibility issue
Browse files Browse the repository at this point in the history
  • Loading branch information
napernik committed Mar 25, 2022
1 parent 3de916e commit 8013a5f
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions Composite/Core/Serialization/CompositeSerializationBinder.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Reflection;
using System.Runtime.Serialization;
using Composite.C1Console.Elements;
using Composite.C1Console.Security;
using Composite.Core.Types;
using Composite.Data;
Expand Down Expand Up @@ -42,15 +43,17 @@ public override Type BindToType(string assemblyName, string typeName)
if (result != null) return result;
}

if (!TypeIsSupported(assemblyName, typeName))
var type = base.BindToType(assemblyName, typeName);

if (!TypeIsSupported(assemblyName, typeName, type))
{
throw new NotSupportedException("Not supported object type");
throw new NotSupportedException($"Not supported object type '{typeName}'");
}

return base.BindToType(assemblyName, typeName);
return type;
}

private bool TypeIsSupported(string assemblyName, string typeName)
private bool TypeIsSupported(string assemblyName, string typeName, Type type)
{
assemblyName = new AssemblyName(assemblyName).Name;

Expand All @@ -65,11 +68,13 @@ private bool TypeIsSupported(string assemblyName, string typeName)
}
}

var type = base.BindToType(assemblyName, typeName);
return type != null
&& (type.IsEnum
|| typeof(EntityToken).IsAssignableFrom(type)
|| typeof(IDataId).IsAssignableFrom(type));
|| typeof(SearchToken).IsAssignableFrom(type)
|| typeof(IDataId).IsAssignableFrom(type)
|| type == typeof(DataSourceId)
|| type == typeof(DataScopeIdentifier));
}
}
}

0 comments on commit 8013a5f

Please sign in to comment.