Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support generic MessagePackFormatterAttribute #902

Merged
merged 1 commit into from
May 8, 2020

Conversation

neuecc
Copy link
Member

@neuecc neuecc commented Apr 30, 2020

discussed in #892

currently [MessagePackFromatter(type)] does not support generics.
This is inconvenient for custom formatters to generic types.

This PR adds support [MessagePackFormatter(typeof(Formatter<>)) to [MessagePackFroamtter(typeof(Formatter<T>))].

[MessagePackFormatter(typeof(TestFooFormatter<>))]
public class TestFoo<T>
{
    public T MyProperty { get; set; }
}

public class TestFooFormatter<T> : IMessagePackFormatter<TestFoo<T>>
{
    public TestFoo<T> Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
    {
        return new TestFoo<T> { MyProperty = options.Resolver.GetFormatterWithVerify<T>().Deserialize(ref reader, options) };
    }

    public void Serialize(ref MessagePackWriter writer, TestFoo<T> value, MessagePackSerializerOptions options)
    {
        options.Resolver.GetFormatterWithVerify<T>().Serialize(ref writer, value.MyProperty, options);
    }
}

@neuecc neuecc requested a review from AArnott April 30, 2020 01:44
@AArnott AArnott added this to the v2.1 milestone May 4, 2020
@neuecc neuecc merged commit 0f86456 into master May 8, 2020
@neuecc neuecc deleted the generic-msgpackfmtattr branch May 8, 2020 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants