-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCountry.cs
More file actions
34 lines (29 loc) · 1.03 KB
/
Country.cs
File metadata and controls
34 lines (29 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
namespace ValueObjects.Contacts
{
public class Country : ValueObject
{
private readonly string code;
private Country(string twoLetterCountryCode)
{
Ensure.Argument.NotNullOrEmpty(twoLetterCountryCode, nameof(twoLetterCountryCode));
Ensure.Argument.Is(Countries.Instance.IsValid(twoLetterCountryCode), $"Invalid country code ({twoLetterCountryCode}).");
code = twoLetterCountryCode.ToUpperInvariant();
}
public static Country FromCode(string twoLetterCountryCode)
{
return new Country(twoLetterCountryCode);
}
protected override IEnumerable<object> GetAtomicValues()
{
yield return code;
}
public static implicit operator string(Country country)
{
return country.code;
}
public static explicit operator Country(string twoLetterCountryCode)
{
return new Country(twoLetterCountryCode);
}
}
}