58 lines
1.8 KiB
C#
58 lines
1.8 KiB
C#
|
//----------------------------------------------------------------
|
||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||
|
//----------------------------------------------------------------
|
||
|
|
||
|
namespace System.ServiceModel.Discovery.Configuration
|
||
|
{
|
||
|
using System.ComponentModel;
|
||
|
using System.ComponentModel.Design.Serialization;
|
||
|
using System.Globalization;
|
||
|
|
||
|
public class DiscoveryVersionConverter : TypeConverter
|
||
|
{
|
||
|
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
||
|
{
|
||
|
if (typeof(string) == sourceType)
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
return base.CanConvertFrom(context, sourceType);
|
||
|
}
|
||
|
|
||
|
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
|
||
|
{
|
||
|
if (typeof(InstanceDescriptor) == destinationType)
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
return base.CanConvertTo(context, destinationType);
|
||
|
}
|
||
|
|
||
|
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
||
|
{
|
||
|
if (value is string)
|
||
|
{
|
||
|
return DiscoveryVersion.FromName((string)value);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return base.ConvertFrom(context, culture, value);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
|
||
|
{
|
||
|
if (typeof(string) == destinationType && value is DiscoveryVersion)
|
||
|
{
|
||
|
return ((DiscoveryVersion)value).Name;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return base.ConvertTo(context, culture, value, destinationType);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|