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

Feature request: Add ToLowerInvariantStringFast() and ToUpperInvariantStringFast() #36

Open
rmja opened this issue Aug 19, 2022 · 1 comment

Comments

@rmja
Copy link

rmja commented Aug 19, 2022

Example implementation could be something like:

        private static class LowerInvariant
        {
            public static readonly string Minute = nameof(Minute).ToLowerInvariant();
            public static readonly string Hour = nameof(Hour).ToLowerInvariant();
            public static readonly string Day = nameof(Day).ToLowerInvariant();
            public static readonly string Week = nameof(Week).ToLowerInvariant();
            public static readonly string Month = nameof(Month).ToLowerInvariant();
            public static readonly string Year = nameof(Year).ToLowerInvariant();
        }

        public static string ToLowerInvariantStringFast(this Period value)
            => value switch
            {
                Period.Minute => LowerInvariant.Minute,
                Period.Hour => LowerInvariant.Hour,
                Period.Day => LowerInvariant.Day,
                Period.Week => LowerInvariant.Week,
                Period.Month => LowerInvariant.Month,
                Period.Year => LowerInvariant.Year,
                _ => value.ToStringFast().ToLowerInvariant(),
            };

This would allow for zero allocation conversions to lower string instead of Period.Hour.ToStringFast().ToLowerInvariant().

Same idea goes for ToUpperInvariantStringFast().

@dylanvdmerwe
Copy link

Great idea.

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

2 participants