Skip to content

Instantly share code, notes, and snippets.

@poulfoged
Created September 16, 2015 09:46
Show Gist options
  • Save poulfoged/17ba390b4176691c7ecc to your computer and use it in GitHub Desktop.
Save poulfoged/17ba390b4176691c7ecc to your computer and use it in GitHub Desktop.
internal class ShortNameSerializationBinder<TBase> : DefaultSerializationBinder where TBase : class
{
private static Dictionary<string, Type> types;
public ShortNameSerializationBinder()
{
types = ReflectiveEnumerator.GetEnumerableOfType<TBase>().ToDictionary(i => i.Name, i => i);
}
public override void BindToName(Type serializedType, out string assemblyName, out string typeName)
{
assemblyName = null;
typeName = serializedType.Name;
}
public override Type BindToType(string assemblyName, string typeName)
{
return types[typeName];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment