public ConvertTo ( ITypeDescriptorContext context, |
||
context | ITypeDescriptorContext | Additional context for conversion. |
culture | The culture to use for conversion. | |
value | object | The |
destinationType | The type of the destination object. | |
Результат | object |
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (null != value && this.CanConvertTo(context, destinationType))
{
var s = string.Empty;
var mode = (LoggingPolicies)value;
// Return the logging modes command line form.
foreach (LoggingPolicies val in Enum.GetValues(typeof(LoggingPolicies)))
{
if (0 != (val & mode) && LoggingPolicies.All != val)
{
s += ModeToCharMap[val];
}
}
return s;
}
return base.ConvertTo(context, culture, value, destinationType);
}
public void ConvertLoggingModesToShortForm() { var converter = new LoggingPoliciesConverter(); Assert.IsTrue(converter.CanConvertTo(typeof(string))); Assert.IsFalse(converter.CanConvertTo(this.GetType())); var mode = (string)converter.ConvertTo(LoggingPoliciesConverterTests.Default, typeof(string)); CollectionAssert.AreEquivalent("oicewarmup".ToArray(), mode.ToArray()); mode = (string)converter.ConvertTo(LoggingPoliciesConverterTests.Default | LoggingPolicies.FlushEachLine, typeof(string)); CollectionAssert.AreEquivalent("oicewarmup!".ToArray(), mode.ToArray()); }