public void TesReflectionWithConverter2() { var ser = new SLJsonSerializer(); TestStringConversion(ser, null); ser.RegisterConverter <string>(x => x ?? string.Empty); TestStringConversion(ser, string.Empty); ser.RegisterConverter <string>(x => x ?? "empty"); TestStringConversion(ser, "empty"); }
public void TesReflectionWithConverter1() { var ser = new SLJsonSerializer(); const string prefix = "prefix: "; ser.RegisterConverter <DateTime>(x => prefix + x.ToString(@"yyyy\-MM\-dd HH\:mm\:ss", CultureInfo.InvariantCulture)); var o1 = new ExampleOuter(); o1.PropertyDateTime = new DateTime(1950, 7, 20, 12, 34, 56); string s = ser.Serialize(o1); Assert.IsTrue(s.Contains(prefix + o1.PropertyDateTime.ToString(@"yyyy\-MM\-dd HH\:mm\:ss", CultureInfo.InvariantCulture))); var des = new SLJsonDeserializer(); des.RegisterConverter <DateTime>(x => { string z = x.Substring(x.IndexOf(prefix) + prefix.Length); return(DateTime.Parse(z, CultureInfo.InvariantCulture)); }); var o2 = des.Deserialize <ExampleOuter>(s); Assert.AreEqual(o1.PropertyDateTime, o2.PropertyDateTime); }