/
ColorStruct.cs
79 lines (68 loc) · 2 KB
/
ColorStruct.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
68
69
70
71
72
73
74
75
76
77
78
79
using System;
namespace Car.Domain
{
public class Color
{
public readonly struct Color: IEquatable<Color>
{
public Color(string hue, bool metallic)
{
BasicPallete = false;
Hue = hue;
Metallic = metallic;
if (hue == "white" && !metallic)
{
BasicPallete = true;
}
}
public string Hue { get; }
public bool Metallic { get; }
public bool BasicPallete { get; }
public Color Repaint(string hue, bool metallic)
{
return new Color(hue, metallic);
}
public override bool Equals(object obj)
{
if (!(obj is Color)) return false;
return this.Equals((Color)obj);
}
public bool Equals(Color otherColor)
{
if (Object.ReferenceEquals(otherColor, null))
{
return false;
}
if (Object.ReferenceEquals(this, otherColor))
{
return true;
}
if (this.GetType() != otherColor.GetType())
{
return false;
}
return (Hue == otherColor.Hue) && (Metallic == otherColor.Metallic);
}
public static bool operator ==(Color leftColor, Color rightColor)
{
if (Object.ReferenceEquals(leftColor, null))
{
if (Object.ReferenceEquals(rightColor, null))
{
// null == null = true
return true;
}
return false;
}
return leftColor.Equals(rightColor);
}
public static bool operator !=(Color leftColor, Color rightColor)
{
return !(leftColor == rightColor);
}
public override int GetHashCode()
{
return (Hue.GetHashCode() * 0x100000) + (Metallic.GetHashCode() * 0x1000) + BasicPallete.GetHashCode();
}
}
}