public virtual TEnum ConvertFromString(string s) { var pair = Pairs.FirstOrDefault(kvp => kvp.Value.Equals(s, StringComparison.OrdinalIgnoreCase)); // ReSharper disable once SuspiciousTypeConversion.Global if (EqualityComparer <KeyValuePair <TEnum, string> > .Default.Equals(pair)) { throw new ArgumentException($"Unknown {EntityString}: {s}"); } return(pair.Key); }