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

Is it possible to register a global formatter without property attribute? #363

Open
xhuan8 opened this issue Jan 21, 2025 · 0 comments
Open

Comments

@xhuan8
Copy link

xhuan8 commented Jan 21, 2025

I have a class "LImage" with a custom formatter, after register it with MemoryPackFormatterProvider.Register(new LImage.SerializationSurrogate());, it works fine.

But if there is another class contains "LImage" as property, then MemoryPack will not notice the custom formatter, I have to add attribute for this property:

public sealed class LImageFormatterAttribute : MemoryPackCustomFormatterAttribute<LImage>
{
    public override IMemoryPackFormatter<LImage> GetFormatter()
    {
        return new LImage.SerializationSurrogate();
    }
}

[MemoryPackable]
public partial class SomeImage
{
    private LImage? image;
    private List<LImage> list = new List<LImage>();

    [LImageFormatter]
    public LImage? Image { get => image; set => image = value; }
    public List<LImage> List { get => list; set => list = value; }
}

Is it possible to register it globally then I don't need add attribute for every property?

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

No branches or pull requests

1 participant