This project has moved. For the latest updates, please go here.
1
Vote

case insensitive for custom color of event types.

description

    public ConsoleColor GetConsoleColor(TraceEventType eventType)
    {
        var key = eventType.ToString() + "Color";
        if (Attributes.ContainsKey(key))
        {
            var setting = Attributes[key];
            if (Enum.IsDefined(typeof (ConsoleColor), setting))
            {
                return (ConsoleColor) Enum.Parse(typeof (ConsoleColor), setting);
            }
        }

comments

zijianhuang wrote May 30, 2014 at 12:58 PM

no need. Just 16 colors.

** Closed by zijianhuang 05/30/2014 5:58AM

sgryphon wrote Mar 13, 2016 at 10:49 PM

Easy fix; it might make for lazy configs if allow case, but should be able to simply use Enum.Parse(typeof(ConsoleColor), setting, true); which is the ignoreCase version of the method.

zijianhuang wrote Jun 10 at 4:31 AM

But IsDefined() is case-sensitive.

It may be better to use Enum.TryParse() which is however available only in .NET 4.

Though technically I could remove isDefined and catch exception that EnumParse may throw, however, this may break the original design intent that did not want to trigger any exception throwing.

Let's improve this when moving away from .net 2.