sourcegit/src/Models/User.cs

41 lines
1.2 KiB
C#
Raw Normal View History

using System.Collections.Concurrent;
2020-07-03 00:24:31 -07:00
namespace SourceGit.Models
{
public class User
{
public static readonly User Invalid = new User();
2020-07-03 00:24:31 -07:00
public string Name { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
2020-07-03 00:24:31 -07:00
public override bool Equals(object obj)
{
if (obj == null || !(obj is User))
return false;
var other = obj as User;
return Name == other.Name && Email == other.Email;
}
2020-07-03 00:24:31 -07:00
public override int GetHashCode()
{
return base.GetHashCode();
}
2020-07-03 00:24:31 -07:00
public static User FindOrAdd(string data)
{
return _caches.GetOrAdd(data, key =>
{
var nameEndIdx = key.IndexOf('<', System.StringComparison.Ordinal);
var name = nameEndIdx >= 2 ? key.Substring(0, nameEndIdx - 1) : string.Empty;
var email = key.Substring(nameEndIdx + 1);
return new User() { Name = name, Email = email };
});
2020-07-03 00:24:31 -07:00
}
private static ConcurrentDictionary<string, User> _caches = new ConcurrentDictionary<string, User>();
2020-07-03 00:24:31 -07:00
}
}