-
Notifications
You must be signed in to change notification settings - Fork 1
/
User.cs
108 lines (88 loc) · 2.37 KB
/
User.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System;
using System.Collections.Generic;
using UserStorageServices.CustomAttributes;
namespace UserStorageServices
{
/// <summary>
/// Represents a user.
/// </summary>
[Serializable]
public class User : IEquatable<User>
{
#region Properties
/// <summary>
/// Generates and gets an user id.
/// </summary>
public int Id { get; set; }
/// <summary>
/// Gets or sets a user first name.
/// </summary>
[ValidateMaxLength(20)]
[ValidateNotNullOrEmpty]
[ValidateRegex("([A-Za-z])\\w+")]
public string FirstName { get; set; }
/// <summary>
/// Gets or sets a user last name.
/// </summary>
[ValidateMaxLength(25)]
[ValidateNotNullOrEmpty]
[ValidateRegex("([A-Za-z])\\w+")]
public string LastName { get; set; }
/// <summary>
/// Gets or sets a user age.
/// </summary>
[ValidateMinMax(18, 110)]
public int Age { get; set; }
#endregion
#region Equality comparison
public static bool operator ==(User lhs, User rhs)
{
if (ReferenceEquals(lhs, rhs))
{
return true;
}
if (ReferenceEquals(lhs, null) || ReferenceEquals(rhs, null))
{
return false;
}
return lhs.Equals(rhs);
}
public static bool operator !=(User lhs, User rhs)
{
return !(lhs == rhs);
}
public bool Equals(User other)
{
if (ReferenceEquals(null, other))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return Id.Equals(other.Id);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != this.GetType())
{
return false;
}
return Equals((User)obj);
}
public override int GetHashCode()
{
return Id.GetHashCode();
}
#endregion
}
}