Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lookup Extensions #4

Open
niemyjski opened this issue Oct 30, 2017 · 1 comment
Open

Lookup Extensions #4

niemyjski opened this issue Oct 30, 2017 · 1 comment

Comments

@niemyjski
Copy link

niemyjski commented Oct 30, 2017

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);
        }
@niemyjski
Copy link
Author

Would you like me to submit a pr for the above minus the alias lookup?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant