public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (null != value && this.CanConvertFrom(context, value.GetType()))
{
var s = value as string;
var mode = LoggingPolicies.None;
// Attempt the simple coversion.
if (TryParse(s, out mode))
{
return mode;
}
else
{
// Try parsing the logging command line options.
foreach (var c in s)
{
if (CharToModeMap.ContainsKey(c))
{
mode |= CharToModeMap[c];
}
else if ('+' == c)
{
throw new ArgumentException(Resources.Error_UnsupportedLoggingMode, "value");
}
else
{
var message = String.Format(CultureInfo.CurrentCulture, Resources.Error_InvalidLoggingMode, c);
throw new ArgumentException(message, "value");
}
}
return mode;
}
}
return base.ConvertFrom(context, culture, value);
}