Пример #1
0
        public void ChangeType_Numerics()
        {
            var ics = new DeepConvertSettings
            {
                Provider = CultureInfo.InvariantCulture,
                Format   = "0.00"
            };
            var decs = new DeepConvertSettings
            {
                Provider = CultureInfo.GetCultureInfo("de-DE"),
                Format   = "0.00"
            };

            Assert.AreEqual(20, DeepConvert.ChangeType <byte>(20));
            Assert.AreEqual("20", DeepConvert.ChangeType <string>(20.0));
            Assert.AreEqual("20.00", DeepConvert.ChangeType <string>(20.0, ics));
            Assert.AreEqual("20,00", DeepConvert.ChangeType <string>(20.0, decs));
            Assert.AreEqual(false, DeepConvert.ChangeType <bool>(0));
            Assert.AreEqual(true, DeepConvert.ChangeType <bool>(20));
            Assert.AreEqual(false, DeepConvert.ChangeType <bool>(0.0));
            Assert.AreEqual(true, DeepConvert.ChangeType <bool>(20.0));
            Assert.AreEqual(1, DeepConvert.ChangeType <byte>(true));
            Assert.AreEqual(100, DeepConvert.ChangeType <float>(100));
            Assert.AreEqual(100, DeepConvert.ChangeType <float>("100"));
            Assert.AreEqual(100, DeepConvert.ChangeType <float>("100.0", ics));
            Assert.AreEqual(100, DeepConvert.ChangeType <double>("100"));
            Assert.AreEqual(100, DeepConvert.ChangeType <double>("100.0", ics));
            Assert.AreEqual(100, DeepConvert.ChangeType <decimal>("100"));
            Assert.AreEqual(100, DeepConvert.ChangeType <decimal>("100.0", ics));
            Assert.AreEqual(100, DeepConvert.ChangeTypeInvariant <decimal>("100.0"));
            Assert.AreEqual(100, DeepConvert.ChangeTypeInvariant <decimal>("100.0", decs));
        }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DeepConvertSettings"/> class from another
 /// instance.
 /// </summary>
 /// <param name="source">The initial settings.</param>
 public DeepConvertSettings(DeepConvertSettings source)
 {
     Provider        = source.Provider;
     Format          = source.Format;
     DateNumericKind = source.DateNumericKind;
     DateTimeStyles  = source.DateTimeStyles;
     Encoding        = source.Encoding;
 }
Пример #3
0
        public void ChangeType_Exponential()
        {
            var ics = new DeepConvertSettings
            {
                Provider = CultureInfo.InvariantCulture
            };
            var decs = new DeepConvertSettings
            {
                Provider = new CultureInfo("de-DE")
            };

            Assert.AreEqual(100, DeepConvert.ChangeType <float>("1.00E+02", ics));
            Assert.AreEqual(100, DeepConvert.ChangeType <double>("1.00E+02", ics));
            Assert.AreEqual(100, DeepConvert.ChangeType <decimal>("1.00E+02", ics));
            Assert.AreEqual(100, DeepConvert.ChangeType <decimal>("1,00E+02", decs));
        }
Пример #4
0
		public void SetValue(object instance, string name, object value, DeepConvertSettings settings)
		{
			setter(instance, name, value, settings);
		}
Пример #5
0
 /// <summary>
 /// Returns a <see cref="uint"/> value that is equivalent to the specified object.
 /// </summary>
 /// <param name="value">The data to convert.</param>
 /// <param name="settings">The conversion settings.</param>
 /// <returns>A <see cref="uint"/> value that is equivalent to <paramref name="value"/>.</returns>
 public static uint ToUInt32(object value, DeepConvertSettings settings) =>
 ChangeType <uint>(value, settings);
Пример #6
0
 /// <summary>
 /// Returns a <see cref="sbyte"/> value that is equivalent to the specified object.
 /// </summary>
 /// <param name="value">The data to convert.</param>
 /// <param name="settings">The conversion settings.</param>
 /// <returns>A <see cref="sbyte"/> value that is equivalent to <paramref name="value"/>.</returns>
 public static sbyte ToSByte(object value, DeepConvertSettings settings) =>
 ChangeType <sbyte>(value, settings);
Пример #7
0
 /// <summary>
 /// Returns a <see cref="short"/> value that is equivalent to the specified object.
 /// </summary>
 /// <param name="value">The data to convert.</param>
 /// <param name="settings">The conversion settings.</param>
 /// <returns>A <see cref="short"/> value that is equivalent to <paramref name="value"/>.</returns>
 public static short ToInt16(object value, DeepConvertSettings settings) =>
 ChangeType <short>(value, settings);
Пример #8
0
 /// <summary>
 /// Returns a list of the specified type whose value is equivalent to the specified
 /// object.
 /// </summary>
 /// <param name="value">The data to convert.</param>
 /// <param name="settings">The conversion settings.</param>
 /// <returns>A list whose value is equivalent to <paramref name="value"/>.</returns>
 public static List <T> ToList <T>(object value, DeepConvertSettings settings) =>
 ChangeType <List <T> >(value, settings);
Пример #9
0
 /// <summary>
 /// Returns a dictionary of the specified type whose value is equivalent to the specified
 /// object.
 /// </summary>
 /// <param name="value">The data to convert.</param>
 /// <param name="settings">The conversion settings.</param>
 /// <returns>A dictionary whose value is equivalent to <paramref name="value"/>.</returns>
 public static Dictionary <TKey, TValue> ToDictionary <TKey, TValue>(object value, DeepConvertSettings settings) =>
 ChangeType <Dictionary <TKey, TValue> >(value, settings);
Пример #10
0
 /// <summary>
 /// Returns a <see cref="string"/> value that is equivalent to the specified object.
 /// </summary>
 /// <param name="value">The data to convert.</param>
 /// <param name="settings">The conversion settings.</param>
 /// <returns>A <see cref="string"/> value that is equivalent to <paramref name="value"/>.</returns>
 public static string ToString(object value, DeepConvertSettings settings) =>
 ChangeType <string>(value, settings);
Пример #11
0
 /// <summary>
 /// Returns an array of the specified type whose value is equivalent to the specified
 /// object.
 /// </summary>
 /// <param name="value">The data to convert.</param>
 /// <param name="settings">The conversion settings.</param>
 /// <returns>An array whose value is equivalent to <paramref name="value"/>.</returns>
 public static T[] ToArray <T>(object value, DeepConvertSettings settings) =>
 ChangeType <T[]>(value, settings);
Пример #12
0
 /// <summary>
 /// Returns a <see cref="bool"/> value that is equivalent to the specified object.
 /// </summary>
 /// <param name="value">The data to convert.</param>
 /// <param name="settings">The conversion settings.</param>
 /// <returns>A <see cref="bool"/> value that is equivalent to <paramref name="value"/>.</returns>
 public static bool ToBoolean(object value, DeepConvertSettings settings) =>
 ChangeType <bool>(value, settings);
Пример #13
0
 /// <summary>
 /// Returns a <see cref="double"/> value that is equivalent to the specified object.
 /// </summary>
 /// <param name="value">The data to convert.</param>
 /// <param name="settings">The conversion settings.</param>
 /// <returns>A <see cref="double"/> value that is equivalent to <paramref name="value"/>.</returns>
 public static double ToDouble(object value, DeepConvertSettings settings) =>
 ChangeType <double>(value, settings);
Пример #14
0
 /// <summary>
 /// Returns a <see cref="float"/> value that is equivalent to the specified object.
 /// </summary>
 /// <param name="value">The data to convert.</param>
 /// <param name="settings">The conversion settings.</param>
 /// <returns>A <see cref="float"/> value that is equivalent to <paramref name="value"/>.</returns>
 public static float ToSingle(object value, DeepConvertSettings settings) =>
 ChangeType <float>(value, settings);
Пример #15
0
 /// <summary>
 /// Returns a <see cref="decimal"/> value that is equivalent to the specified object.
 /// </summary>
 /// <param name="value">The data to convert.</param>
 /// <param name="settings">The conversion settings.</param>
 /// <returns>A <see cref="decimal"/> value that is equivalent to <paramref name="value"/>.</returns>
 public static decimal ToDecimal(object value, DeepConvertSettings settings) =>
 ChangeType <decimal>(value, settings);
Пример #16
0
 /// <summary>
 /// Returns a <see cref="long"/> value that is equivalent to the specified object.
 /// </summary>
 /// <param name="value">The data to convert.</param>
 /// <param name="settings">The conversion settings.</param>
 /// <returns>A <see cref="long"/> value that is equivalent to <paramref name="value"/>.</returns>
 public static long ToInt64(object value, DeepConvertSettings settings) =>
 ChangeType <long>(value, settings);