-
-
Save dcomartin/dd0d923644437daabe3ffe7fba04ec56 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public readonly record struct Username | |
{ | |
private string Value { get; } | |
public Username(string value) | |
{ | |
if (string.IsNullOrEmpty(value)) | |
{ | |
throw new ArgumentNullException(nameof(value)); | |
} | |
Value = value; | |
} | |
public override string ToString() | |
{ | |
if (Value == null) | |
{ | |
throw new InvalidCastException("Cannot create default Username"); | |
} | |
return Value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Because you can do default(Username) in which Value will be null.