Mercurial > pub > bltoolkit
view Source/Mapping/MemberMappers/JSONSerialisationMapper.cs @ 7:99cd4f3947d8
Закомментированы строки мешающие добавлению авиа дежурств.
author | nickolay |
---|---|
date | Fri, 27 Oct 2017 18:26:29 +0300 |
parents | f990fcb411a9 |
children |
line wrap: on
line source
using System; using System.IO; using System.Runtime.Serialization.Json; using System.Text; namespace BLToolkit.Mapping.MemberMappers { public class JSONSerialisationMapper : MemberMapper { public override void SetValue(object o, object value) { if (value != null) this.MemberAccessor.SetValue(o, Deserialize(value.ToString())); } public override object GetValue(object o) { return this.serialize(this.MemberAccessor.GetValue(o)); } private string serialize(object obj) { if (obj == null) return null; DataContractJsonSerializer ser = new DataContractJsonSerializer(this.Type); MemoryStream ms = new MemoryStream(); ser.WriteObject(ms, obj); string jsonString = Encoding.UTF8.GetString(ms.ToArray()); ms.Close(); return jsonString; } object Deserialize(string txt) { object retVal = null; if (string.IsNullOrEmpty(txt)) return null; try { DataContractJsonSerializer ser = new DataContractJsonSerializer(this.Type); MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(txt)); retVal = ser.ReadObject(ms); } catch (Exception) { } return retVal; } } }