sourcegit/src/Models/User.cs

47 lines
1.3 KiB
C#
Raw Normal View History

using System.Collections.Generic;
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)
{
if (_caches.TryGetValue(data, out var value))
{
return value;
}
else
{
var nameEndIdx = data.IndexOf('<', System.StringComparison.Ordinal);
var name = nameEndIdx >= 2 ? data.Substring(0, nameEndIdx - 1) : string.Empty;
var email = data.Substring(nameEndIdx + 1);
User user = new User() { Name = name, Email = email };
_caches.Add(data, user);
return user;
}
2020-07-03 00:24:31 -07:00
}
private static Dictionary<string, User> _caches = new Dictionary<string, User>();
2020-07-03 00:24:31 -07:00
}
}