Schema.NET icon indicating copy to clipboard operation
Schema.NET copied to clipboard

Consider Implementing `IParseable` in .NET 6

Open RehanSaeed opened this issue 3 years ago • 3 comments

Describe the feature

See https://devblogs.microsoft.com/dotnet/preview-features-in-net-6-generic-math/#static-abstracts-in-interfaces

public interface IParseable<TSelf>
    where TSelf : IParseable<TSelf>
{
    static abstract TSelf Parse(string s, IFormatProvider? provider);

    static abstract bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out TSelf result);
}

RehanSaeed avatar Aug 11 '21 10:08 RehanSaeed

Interesting - you thinking have this on Thing or maybe each of our derived types implements it? Should mostly be able to pass it off to the SchemaSerializer class.

Turnerj avatar Aug 11 '21 14:08 Turnerj

I was thinking it would be nice to have it on Thing as just a convenience method.

RehanSaeed avatar Aug 11 '21 14:08 RehanSaeed

If we can't make use of #310 (source generators from S.T.J), we could even use these methods to output custom serialization for a type from our own source generator. That is to say, we'd generate it ourselves when we generate the model.

Turnerj avatar Aug 18 '21 09:08 Turnerj