/// <summary> /// Tries to load the value. /// </summary> /// <param name="name">The name.</param> /// <param name="valueType">Type of the value.</param> /// <param name="value">The value.</param> /// <returns></returns> public bool TryLoadValue(string name, Type valueType, out object value) { if (!ReadValue(name, out var rawValue)) { value = null; return(false); } value = Transtyper.FromPersistent(rawValue, valueType); return(true); }
[TestMethod] public void BoolToIntTest() => Assert.AreEqual(true, Transtyper.Transtype <bool>(1));
[TestMethod] public void IntToBoolTest() => Assert.AreEqual(1, Transtyper.Transtype <int>(true));
[TestMethod] public void EnumToIntTest() => Assert.AreEqual(3, Transtyper.Transtype <int>(E.C));
[TestMethod] public void IntToEnumTest() => Assert.AreEqual(E.A, Transtyper.Transtype <E>(1));
[TestMethod] public void EnumToStringTest() => Assert.AreEqual("C", Transtyper.Transtype <string>(E.C));
[TestMethod] public void StringToEnumTest() => Assert.AreEqual(E.B, Transtyper.Transtype <E>("B"));
[TestMethod] public void VersionToStringTest() => Assert.AreEqual("7.8", Transtyper.Transtype <string>(new Version(7, 8)));
[TestMethod] public void StringToVersionTest() => Assert.AreEqual(new Version(5, 6), Transtyper.Transtype <Version>("5.6"));
[TestMethod] public void BoolToStringTest() => Assert.AreEqual("False", Transtyper.Transtype <string>(false));
[TestMethod] public void StringToBool2Test() => Assert.AreEqual(false, Transtyper.Transtype <bool>("false"));
[TestMethod] public void StringToBoolTest() => Assert.AreEqual(true, Transtyper.Transtype <bool>("true"));
[TestMethod] public void IntToStringTest() => Assert.AreEqual("34", Transtyper.Transtype <string>(34));
[TestMethod] public void StringToIntTest() => Assert.AreEqual(12, Transtyper.Transtype <int>("12"));
/// <summary> /// Saves the value. /// </summary> /// <param name="name">The name.</param> /// <param name="valueType">Type of the value.</param> /// <param name="value">The value.</param> public void SaveValue(string name, Type valueType, object value) { var persistedValue = Transtyper.ToPersistent(value, Mappings, out var tag); WriteValue(name, persistedValue, tag); }