-
Notifications
You must be signed in to change notification settings - Fork 0
/
PokemonType.cs
67 lines (57 loc) · 2.05 KB
/
PokemonType.cs
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
namespace Pokegraph.Domain.Pokemon;
public class PokemonType : ValueObject<PokemonType>
{
public string Name { get; set; }
public static PokemonType From(string typeName)
{
if (string.IsNullOrWhiteSpace(typeName))
throw new DomainException("Pokemon's type cannot be null or whitespace.");
var pokemonType = new PokemonType(typeName);
if (!_supportedTypes.Contains(pokemonType))
throw new DomainException($"Pokemon's [{typeName}] type is not supported.");
return pokemonType;
}
public static PokemonType Grass => new("Grass");
public static PokemonType Fire => new("Fire");
public static PokemonType Water => new("Water");
public static PokemonType Bug => new("Bug");
public static PokemonType Normal => new("Normal");
public static PokemonType Poison => new("Poison");
public static PokemonType Electric => new("Electric");
public static PokemonType Ground => new("Ground");
public static PokemonType Psychic => new("Psychic");
public static PokemonType Fighting => new("Fighting");
public static PokemonType Rock => new("Rock");
public static PokemonType Ghost => new("Ghost");
public static PokemonType Ice => new("Ice");
public static PokemonType Dragon => new("Dragon");
protected override IEnumerable<object> GetEqualityComponents()
{
yield return Name;
}
protected PokemonType() { }
private static IEnumerable<PokemonType> _supportedTypes
{
get
{
yield return Grass;
yield return Fire;
yield return Water;
yield return Bug;
yield return Normal;
yield return Poison;
yield return Electric;
yield return Ground;
yield return Psychic;
yield return Fighting;
yield return Rock;
yield return Ghost;
yield return Ice;
yield return Dragon;
}
}
private PokemonType(string typeName)
{
Name = typeName;
}
}