Open niemyjski opened 7 years ago
I have some lookup extensions.. I could submit a pr but I currently have alias support built in....
public List<string> GetAllNames() { return Country.Countries.Select(c => c.Name).ToList(); } public List<Country> GetCountryByPartialName(string name) { if (string.IsNullOrEmpty(name)) throw new ArgumentNullException(nameof(name)); return Country.Countries.Where(c => CultureInfo.InvariantCulture.CompareInfo.IndexOf(c.Name, name, CompareOptions.IgnoreCase) >= 0).ToList(); } public Country GetCountryByFullName(string name) { if (string.IsNullOrEmpty(name)) throw new ArgumentNullException(nameof(name)); return Country.Countries.FirstOrDefault(c => String.Equals(c.Name, name, StringComparison.InvariantCultureIgnoreCase)); } public Country GetCountryByAlpha2(string code) { if (string.IsNullOrEmpty(code)) throw new ArgumentNullException(nameof(code)); return Country.Countries.FirstOrDefault(c => c.Alpha2Code == code); } public Country GetCountryByAlpha3(string code) { if (string.IsNullOrEmpty(code)) throw new ArgumentNullException(nameof(code)); return Country.Countries.FirstOrDefault(c => c.Alpha3Code == code); } public static Country GetCountryByNumeric(int code) { if (code <= 0 || code > 1000) throw new ArgumentOutOfRangeException(nameof(code)); return Country.Countries.FirstOrDefault(c => c.NumericCode == code); }
Would you like me to submit a pr for the above minus the alias lookup?
I have some lookup extensions.. I could submit a pr but I currently have alias support built in....