Skip to content

Conversation

@valeriob
Copy link
Contributor

Hi,
given object stored for long period of time, this allow the code base to be refactored, because it allow users to customize how a type is resolved.
Here is an usage example :

((MessagePack.Formatters.TypelessFormatter)MessagePack.Formatters.TypelessFormatter.Instance).BindToType = typeName =>
{
if (typeName.StartsWith("SomeNamespace"))
{
typeName = typeName.Replace("SomeNamespace", "AnotherNamespace");
}
return Type.GetType(typeName, false);
};

I'm not entirely happy with usage because of the .Instance and the cast.

@neuecc
Copy link
Member

neuecc commented Dec 18, 2017

Thanks.
TypelessFormatter is not singleton(because to enable configure by [MessagePackFormatterAttribute]).
But I think configuration should share all formatters.

so BindToType okay to make static.
public static Func<string, Type> BindToType { get; set; }.

@valeriob
Copy link
Contributor Author

So this is how it's used :

MessagePack.Formatters.TypelessFormatter.BindToType = typeName =>
{
if (typeName.StartsWith("SomeNamespace"))
{
typeName = typeName.Replace("SomeNamespace", "AnotherNamespace");
}
return Type.GetType(typeName, false);
};

@neuecc
Copy link
Member

neuecc commented Dec 18, 2017

Yes, it is good.

@neuecc neuecc merged commit 4e5c463 into MessagePack-CSharp:master Dec 19, 2017
@neuecc
Copy link
Member

neuecc commented Dec 22, 2017

I've released 1.7.3 that includes this PR, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants