Created
October 29, 2023 04:04
-
-
Save Calabonga/92c35bb51ad818915806bace780c0640 to your computer and use it in GitHub Desktop.
ValueObject implementeation
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 sealed record LastName | |
{ | |
public const int MaxLength = 32; | |
private LastName(string value) | |
{ | |
Value = value; | |
} | |
public string Value { get; private set; } | |
public static LastName Initialize(string lastName) | |
{ | |
if (string.IsNullOrEmpty(lastName)) | |
{ | |
throw new ArgumentNullException(lastName); | |
} | |
if (lastName.Length > MaxLength) | |
{ | |
throw new ArgumentException($"{nameof(LastName)} length is greater than max value ({MaxLength})", lastName); | |
} | |
return new LastName(lastName); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment