Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/Common.Logging/Logging/Configuration/ArgUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,25 +146,25 @@ public static T Coalesce<T>(Predicate<T> predicate, params T[] values) where T :
/// <returns>the successfully parsed value, <paramref name="defaultValue"/> otherwise.</returns>
public static T TryParseEnum<T>(T defaultValue, string stringValue) where T : struct
{
if (!typeof(T).IsEnum)
Type enumType = typeof(T);
if (!enumType.IsEnum)
{
throw new ArgumentException(string.Format("Type '{0}' is not an enum type", typeof(T).FullName));
}

T result = defaultValue;
if (string.IsNullOrEmpty(stringValue))
{
return defaultValue;
}

try
{
result = (T)Enum.Parse(typeof(T), stringValue, true);
// If a string is specified then try to parse and return it
if (!string.IsNullOrEmpty(stringValue))
{
return (T)Enum.Parse(enumType, stringValue, true);
}
}
catch
{
Trace.WriteLine(string.Format("WARN: failed converting value '{0}' to enum type '{1}'", stringValue, defaultValue.GetType().FullName));
}
return result;
return defaultValue;
}

/// <summary>
Expand Down