Humanizer icon indicating copy to clipboard operation
Humanizer copied to clipboard

Humanize for boolean types

Open juniorgasparotto opened this issue 5 years ago • 2 comments

I would like to know if there is or will be support for the "Humanize" method for Boolean types.

juniorgasparotto avatar Jul 20 '20 23:07 juniorgasparotto

Could you provide some examples that you have in mind?

hazzik avatar Jul 21 '20 09:07 hazzik

While this by no means following the pattern in this project, an extension method is how I accomplish this and would be happy to submit a PR with this support matching the expected project behavior.

public static class BooleanExtensions
    {
        /// <summary>
        /// Returns human readable string of Yes/No for the given boolean
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        public static string ToHuman(this bool val)
        {
            return val.ToString().Replace("False", "No").Replace("True", "Yes");
        }
    }

breaker05 avatar Feb 23 '21 01:02 breaker05

I would suggest to write own extension method as it is much easier.

public static string Humanize(this bool val) => val ? "Yes" : "No";

Not sure why would someone want this as a library.

hazzik avatar Mar 04 '24 03:03 hazzik