Skip to content

Missing IParsable<TSelf> and IFormattable interface implementation #39

@timotyturini

Description

@timotyturini

I found this source generator very powerful and I love it, but there is some missing functionality about globalization:

  • IParsable<TSelf> implementation is missing, and the exposed Parse/TryParse method do not accept an IFormatProvider parameter:
// UnitGenerateOptions.ParseMethod

public static SomeInteger Parse(string s)
{
    return new SomeInteger(int.Parse(s));
}

public static bool TryParse(string s, out SomeInteger result)
{
    if (int.TryParse(s, out var r))
    {
        result = new SomeInteger(r);
        return true;
    }
    else
    {
        result = default(SomeInteger);
        return false;
    }
}
  • IFormattable implementation also is missing, with similar drawbacks:
public override string ToString() => value.ToString();

I guess both implementations requires checking the underlying type to ensure that it supports those interfaces and, in that case, implement and pass-through the aforementioned IFormatProvider.

Could be sweet to also expose ToString(string format) methods when available on the underlying type, but without a system interface flagging it, i admit is a bit tricky.

Side note: even i'm developing on C# from 10+ years this is my actual first github interaction, and -if you are OK with it- I do wish to contribute about this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions