public void ConvertTo_String_ReturnsExpected() { var converter = new GuidConverter(); var value = new Guid(0x30da92c0, 0x23e8, 0x42a0, 0xae, 0x7c, 0x73, 0x4a, 0x0e, 0x5d, 0x27, 0x82); Assert.Equal("30da92c0-23e8-42a0-ae7c-734a0e5d2782", converter.ConvertTo(value, typeof(string))); }
/// <summary> /// Extends ConvertTo so that methods that return a specific type object given a Type parameter can be /// used as generic method and casting is not required. /// <example> /// typeconverter.ConvertTo<int>(value); /// </example> /// </summary> public static T ConvertTo <T>(this GuidConverter typeconverter, Object value) { if (typeconverter == null) { throw new ArgumentNullException("typeconverter"); } return((T)typeconverter.ConvertTo(value, typeof(T))); }
/// <summary> /// Extends ConvertTo so that methods that return a specific type object given a Type parameter can be /// used as generic method and casting is not required. /// <example> /// guidconverter.ConvertTo<int>(context, culture, value); /// </example> /// </summary> public static T ConvertTo <T>(this GuidConverter guidconverter, ITypeDescriptorContext context, System.Globalization.CultureInfo culture, Object value) { if (guidconverter == null) { throw new ArgumentNullException("guidconverter"); } return((T)guidconverter.ConvertTo(context, culture, value, typeof(T))); }
public void ConvertTo_InstanceDescriptor_ReturnsExpected() { var converter = new GuidConverter(); var value = new Guid(0x30da92c0, 0x23e8, 0x42a0, 0xae, 0x7c, 0x73, 0x4a, 0x0e, 0x5d, 0x27, 0x82); InstanceDescriptor descriptor = Assert.IsType <InstanceDescriptor>(converter.ConvertTo(value, typeof(InstanceDescriptor))); ConstructorInfo constructor = Assert.IsAssignableFrom <ConstructorInfo>(descriptor.MemberInfo); Assert.Equal(new Type[] { typeof(string) }, constructor.GetParameters().Select(p => p.ParameterType)); Assert.Equal(new object[] { "30da92c0-23e8-42a0-ae7c-734a0e5d2782" }, descriptor.Arguments); }
public void ConvertTo_InvalidValue_ThrowsNotSupportedException(Type destinationType) { var converter = new GuidConverter(); Assert.Throws <NotSupportedException>(() => converter.ConvertTo(new object(), destinationType)); }