forked from sourcegit-scm/sourcegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.cs
More file actions
50 lines (40 loc) · 1.28 KB
/
Copy pathUser.cs
File metadata and controls
50 lines (40 loc) · 1.28 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Collections.Concurrent;
namespace SourceGit.Models
{
public class User
{
public static readonly User Invalid = new User();
public string Name { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public User()
{
// Only used by User.Invalid
}
public User(string data)
{
var nameEndIdx = data.IndexOf('±', StringComparison.Ordinal);
Name = nameEndIdx > 0 ? data.Substring(0, nameEndIdx) : string.Empty;
Email = data.Substring(nameEndIdx + 1);
_hash = data.GetHashCode();
}
public override bool Equals(object obj)
{
return obj is User other && Name == other.Name && Email == other.Email;
}
public override int GetHashCode()
{
return _hash;
}
public static User FindOrAdd(string data)
{
return _caches.GetOrAdd(data, key => new User(key));
}
public override string ToString()
{
return $"{Name} <{Email}>";
}
private static ConcurrentDictionary<string, User> _caches = new ConcurrentDictionary<string, User>();
private readonly int _hash;
}
}