public void ShouldCastToInt() { var castable = new Castable(); int expected = 2; int result = castable.To<int>("2"); Assert.Equal(expected, result); }
public void ShouldCastToDate() { var castable = new Castable(); var expected = new DateTime(2000, 1, 1, 1, 1, 1); var result = castable.To<DateTime>("2000/1/1 01:01:01"); Assert.Equal(expected, result); }
public void ShouldCastToDecimal() { var castable = new Castable(); decimal expected = 2.3m; decimal result = castable.To<decimal>("2.3"); Assert.Equal(expected, result); }
public void ShouldCastToDouble() { var castable = new Castable(); double expected = 2.3; double result = castable.To<double>("2.3"); Assert.Equal(expected, result); }
public void ShouldCastToInt() { var castable = new Castable(); int expected = 2; int result = castable.To <int>("2"); Assert.Equal(expected, result); }
public void ShouldCastToDate() { var castable = new Castable(); var expected = new DateTime(2000, 1, 1, 1, 1, 1); var result = castable.To <DateTime>("2000/1/1 01:01:01"); Assert.Equal(expected, result); }
public void ShouldCastToDouble() { var castable = new Castable(); double expected = 2.3; double result = castable.To <double>("2.3"); Assert.Equal(expected, result); }
public void ShouldCastToDecimal() { var castable = new Castable(); decimal expected = 2.3m; decimal result = castable.To <decimal>("2.3"); Assert.Equal(expected, result); }
public static T To <T>(this object input) { if (typeof(T) == typeof(object)) { return((T)input); } var castable = new Castable(); return(castable.To <T>(input)); }
public static T To <T>(this string input) { var castable = new Castable(); return(castable.To <T>(input)); }
public static T To <T>(this object input, T or) { var castable = new Castable(); return(castable.To(input, or)); }