public ConvertFrom ( ITypeDescriptorContext context, |
||
context | ITypeDescriptorContext | Additional context for conversion. |
culture | The culture to use for conversion. | |
value | object | The |
return | object |
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (null != value && this.CanConvertFrom(context, value.GetType()))
{
string s = value as string;
ReinstallModes mode = 0;
// Attempt the simple coversion.
if (TryParse(s, out mode))
{
return mode;
}
else
{
// Try parsing the REINSTALLMODE property values.
foreach (char c in s)
{
if (CharToModeMap.ContainsKey(c))
{
mode |= CharToModeMap[c];
}
else
{
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Error_InvalidReinstallMode, c), "value");
}
}
return mode;
}
}
return base.ConvertFrom(context, culture, value);
}
public void ConvertShortFormToReinstallModes() { var converter = new ReinstallModesConverter(); Assert.IsTrue(converter.CanConvertFrom(typeof(string))); var mode = (ReinstallModes)converter.ConvertFrom("omUS"); Assert.AreEqual(Default, mode); }