public ToType ( |
||
conversionType | ||
provider | IFormatProvider | |
Résultat | object |
public void CanConvertByte() { var convertible = new DefaultConvertible(byte.MaxValue.ToString()); byte value = convertible.ToByte(CultureInfo.InvariantCulture); Assert.AreEqual(byte.MaxValue, value); object oValue = convertible.ToType(typeof(byte), CultureInfo.InvariantCulture); Assert.AreEqual(byte.MaxValue, oValue); }
public void CanConvertChar() { var convertible = new DefaultConvertible("t"); char value = convertible.ToChar(CultureInfo.InvariantCulture); Assert.AreEqual('t', value); object oValue = convertible.ToType(typeof(char), CultureInfo.InvariantCulture); Assert.AreEqual('t', oValue); }
public void CanConvertBool() { var convertible = new DefaultConvertible("true"); bool value = convertible.ToBoolean(CultureInfo.InvariantCulture); Assert.IsTrue(value); object oValue = convertible.ToType(typeof(bool), CultureInfo.InvariantCulture); Assert.AreEqual(true, oValue); }
public void CanConvertDateTime() { var convertible = new DefaultConvertible("11/05/1605"); DateTime value = convertible.ToDateTime(CultureInfo.InvariantCulture); var actual = new DateTime(1605, 11, 5); Assert.AreEqual(actual, value); object oValue = convertible.ToType(typeof(DateTime), CultureInfo.InvariantCulture); Assert.AreEqual(actual, oValue); }
public void CanConvertDouble() { var convertible = new DefaultConvertible("1.2"); double value = convertible.ToDouble(CultureInfo.InvariantCulture); Assert.AreEqual(1.2, value); object oValue = convertible.ToType(typeof(double), CultureInfo.InvariantCulture); Assert.AreEqual(1.2, oValue); }
public void CanConvertDecimal() { var convertible = new DefaultConvertible("1.3"); decimal value = convertible.ToDecimal(CultureInfo.InvariantCulture); Assert.AreEqual(1.3M, value); object oValue = convertible.ToType(typeof(decimal), CultureInfo.InvariantCulture); Assert.AreEqual(1.3M, oValue); }
public void CanConvertBoolWithComma() { var convertible = new DefaultConvertible("true,false"); Assert.That(convertible.ToType(typeof(bool), CultureInfo.CurrentCulture), Is.EqualTo(true)); Assert.That(convertible.ToBoolean(CultureInfo.CurrentCulture), Is.True); }
public void CanConvertUShort() { var convertible = new DefaultConvertible(ushort.MaxValue.ToString()); ushort value = convertible.ToUInt16(CultureInfo.InvariantCulture); Assert.AreEqual(ushort.MaxValue, value); object oValue = convertible.ToType(typeof(ushort), CultureInfo.InvariantCulture); Assert.AreEqual(ushort.MaxValue, oValue); }
public void FallsBackToTypeConverter() { var convertible = new DefaultConvertible("1.02:03:04.005"); var value = (TimeSpan)convertible.ToType(typeof(TimeSpan), CultureInfo.InvariantCulture); var actual = new TimeSpan(1, 2, 3, 4, 5); Assert.AreEqual(actual, value); }
public void CanConvertULong() { var convertible = new DefaultConvertible(ulong.MaxValue.ToString()); ulong value = convertible.ToUInt64(CultureInfo.InvariantCulture); Assert.AreEqual(ulong.MaxValue, value); object oValue = convertible.ToType(typeof(ulong), CultureInfo.InvariantCulture); Assert.AreEqual(ulong.MaxValue, oValue); }
public void CanConvertInt() { var convertible = new DefaultConvertible(int.MaxValue.ToString()); int value = convertible.ToInt32(CultureInfo.InvariantCulture); Assert.AreEqual(int.MaxValue, value); object oValue = convertible.ToType(typeof(int), CultureInfo.InvariantCulture); Assert.AreEqual(int.MaxValue, oValue); }
public void CanConvertGuid() { Guid actual = Guid.NewGuid(); var convertible = new DefaultConvertible(actual.ToString()); Guid value = convertible.ToGuid(); Assert.AreEqual(actual, value); object oValue = convertible.ToType(typeof(Guid), CultureInfo.InvariantCulture); Assert.AreEqual(actual, oValue); }
public void CanConvertFloat() { var convertible = new DefaultConvertible("1.1"); float value = convertible.ToSingle(CultureInfo.InvariantCulture); Assert.AreEqual(1.1F, value); object oValue = convertible.ToType(typeof(float), CultureInfo.InvariantCulture); Assert.AreEqual(1.1F, oValue); }
public void CanConvertEnum() { var convertible = new DefaultConvertible("Minute"); var value = (WeAre)convertible.ToEnum(typeof(WeAre)); Assert.AreEqual(WeAre.Minute, value); object oValue = convertible.ToType(typeof(WeAre), CultureInfo.InvariantCulture); Assert.AreEqual(WeAre.Minute, oValue); }