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

'Constructors' for alternate data formats #34

Open
simbrett opened this issue Nov 2, 2022 · 2 comments
Open

'Constructors' for alternate data formats #34

simbrett opened this issue Nov 2, 2022 · 2 comments

Comments

@simbrett
Copy link

simbrett commented Nov 2, 2022

Hello,
I'm new to ValueOf so this may be a basic question, but it there a way of creating an object with alternative data formats? For example I would like to represent a telephone number as a long, but I also want to be able to create the object using a string.

So I would like to accept:
1234567890 (long)
But I would also like to create the object using
(123)456-7890 (string)
or 123-456-7890 (string)
or +1 123-45-6789 (string).

In all cases, the actual data would be represented as a long.

I realize that I'm supposed to create the object using TelephoneNumber.From(1234567890)
but can I have the alternate constructors?

Thank you

@mcintyre321
Copy link
Owner


public class TelephoneNumber : ValueOf<long, TelephoneNumber> 
{ 
    public static TelephoneNumber From(string value) => TelephoneNumber.From(long.Parse(value));
}

@simbrett
Copy link
Author

simbrett commented Nov 3, 2022

This is perfect. I don't know why I didn't figure it out. Thank you for your quick response.

This is a great and useful package. Thank you for your work in making it available to us.

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

2 participants