Skip to content

Instantly share code, notes, and snippets.

@Calabonga
Created October 29, 2023 04:04
Show Gist options
  • Save Calabonga/92c35bb51ad818915806bace780c0640 to your computer and use it in GitHub Desktop.
Save Calabonga/92c35bb51ad818915806bace780c0640 to your computer and use it in GitHub Desktop.
ValueObject implementeation
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