/// </summary>
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
- if (sourceType == null)
- {
- throw new ArgumentNullException(nameof(sourceType));
- }
-
- return sourceType == typeof(string) || sourceType == typeof(Uri);
+ return sourceType == typeof(string) || sourceType == typeof(Uri) || base.CanConvertFrom(context, sourceType);
}
/// <summary>
/// </summary>
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
- return destinationType == typeof(string) || destinationType == typeof(Uri) || destinationType == typeof(InstanceDescriptor);
+ return destinationType == typeof(Uri) || destinationType == typeof(InstanceDescriptor) || base.CanConvertTo(context, destinationType);
}
/// <summary>
{
if (destinationType == typeof(InstanceDescriptor))
{
- ConstructorInfo ci = typeof(Uri).GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(string), typeof(UriKind) }, null);
- Debug.Assert(ci != null, "Couldn't find constructor");
- return new InstanceDescriptor(ci, new object[] { uri.OriginalString, uri.IsAbsoluteUri ? UriKind.Absolute : UriKind.Relative });
+ ConstructorInfo ctor = typeof(Uri).GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(string), typeof(UriKind) }, null);
+ Debug.Assert(ctor != null, "Couldn't find constructor");
+ return new InstanceDescriptor(ctor, new object[] { uri.OriginalString, uri.IsAbsoluteUri ? UriKind.Absolute : UriKind.Relative });
}
if (destinationType == typeof(string))
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using System.ComponentModel.Design.Serialization;
+using System.Diagnostics;
using System.Globalization;
+using System.Reflection;
namespace System.ComponentModel
{
/// </summary>
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
- if (sourceType == null)
- throw new ArgumentNullException(nameof(sourceType));
-
- return sourceType == typeof(string) || sourceType == typeof(Version);
+ return sourceType == typeof(string) || sourceType == typeof(Version) || base.CanConvertFrom(context, sourceType);
}
/// <summary>
/// </summary>
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
- return destinationType == typeof(string) || destinationType == typeof(Version);
+ return destinationType == typeof(Version) || destinationType == typeof(InstanceDescriptor) || base.CanConvertTo(context, destinationType);
}
/// <summary>
if (value is Version version)
{
+ if (destinationType == typeof(InstanceDescriptor))
+ {
+ ConstructorInfo ctor = typeof(Version).GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(int), typeof(int), typeof(int), typeof(int) }, null);
+ Debug.Assert(ctor != null, "Couldn't find constructor");
+ return new InstanceDescriptor(ctor, new object[] { version.Major, version.Minor, version.Build, version.Revision });
+ }
+
if (destinationType == typeof(string))
+ {
return version.ToString();
+ }
if (destinationType == typeof(Version))
+ {
return new Version(version.Major, version.Minor, version.Build, version.Revision);
+ }
}
return base.ConvertTo(context, culture, value, destinationType);
[Fact]
public static void CanConvertFrom_WithContext()
{
- CanConvertFrom_WithContext(new object[2, 2]
+ CanConvertFrom_WithContext(new object[3, 2]
{
{ typeof(string), true },
- { typeof(Uri), true }
+ { typeof(Uri), true },
+ { typeof(InstanceDescriptor), true }
},
UriTypeConverterTests.s_converter);
}
{
{ typeof(string), true },
{ typeof(Uri), true },
- { typeof(InstanceDescriptor), true },
+ { typeof(InstanceDescriptor), true }
},
UriTypeConverterTests.s_converter);
}
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using System.ComponentModel.Design.Serialization;
using Xunit;
namespace System.ComponentModel.Tests
[Fact]
public static void CanConvertFrom_WithContext()
{
- CanConvertFrom_WithContext(new object[2, 2]
+ CanConvertFrom_WithContext(new object[3, 2]
{
{ typeof(string), true },
- { typeof(Version), true }
+ { typeof(Version), true },
+ { typeof(InstanceDescriptor), true }
},
VersionConverterTests.s_converter);
}
}
[Fact]
+ public static void CanConvertTo_WithContext()
+ {
+ CanConvertTo_WithContext(new object[3, 2]
+ {
+ { typeof(string), true },
+ { typeof(Version), true },
+ { typeof(InstanceDescriptor), true }
+ },
+ VersionConverterTests.s_converter);
+ }
+
+ [Fact]
public static void ConvertFromNull_WithContext_ThrowsNotSupportedException()
{
Assert.Throws<NotSupportedException>(