public void Serialize(MapPath path, object fromValue, Type fromType, IMapSerializeOptions options, IMapSerializeContext context) { var innerType = fromType.GetGenericArguments()[0]; var innerValue = fromType.GetProperty("Value").GetValue(fromValue); context.Serialize(path, innerValue, innerType, options); }
public void Serialize(MapPath path, object fromValue, Type fromType, IMapSerializeOptions options) { //! ignore path if (options.IsIgnore(path)) { return; } this._serializer.Serialize(path, fromValue, fromType, options, this); }
public IMapMedia <TFrom> From <TFrom>(TFrom fromValue, IMapSerializeOptions <TFrom> options) { if (options == null) { throw new ArgumentNullException(nameof(options)); } return(new MapMedia <TFrom>( this.Serialize(fromValue, typeof(TFrom), options), this._deserializer, this._options, this._config)); }
public bool CanSerialize(MapPath path, object fromValue, Type fromType, IMapSerializeOptions options, IMapSerializeContext context) { if (fromType.Namespace.StartsWith("System")) { return(false); } if (fromType.IsEnum) { return(false); } return(true); }
public IMapMedia From(object fromValue, Type fromType, IMapSerializeOptions options) { if (fromType == null) { throw new ArgumentNullException(nameof(fromType)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } return(new MapMedia( this.Serialize(fromValue, fromType, options), this._deserializer, this._options, this._config)); }
private IMapTable Serialize(object fromValue, Type fromType, IMapSerializeOptions options) { if (fromType == null) { throw new ArgumentNullException(nameof(fromType)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } var table = new MapTable(); var context = new MapSerializeContext(this._serializer, table); this._config.AttachTo(fromType, options); this._serializer.Serialize(MapPath.Root, fromValue, fromType, options, context); return(table.AfterSerialize(options)); }
public void Serialize(MapPath path, object fromValue, Type fromType, IMapSerializeOptions options, IMapSerializeContext context) { var arr = fromValue; var elemType = ArrayUtil.GetElementType(fromType); context.Table.AddToken(path, new MapArrayToken(fromType, elemType)); if (ArrayUtil.IsEnumerable(fromType)) { arr = ArrayUtil.ToArray(elemType, arr); } var count = ArrayUtil.GetCount(arr); for (var i = 0; i < count; ++i) { var value = ArrayUtil.GetValue(arr, i); context.Serialize(path.Append($"{i}"), value, elemType, options); } }
public void Serialize(MapPath path, object fromValue, Type fromType, IMapSerializeOptions options, IMapSerializeContext context) { context.Table.AddToken(path, new MapObjectToken()); var props = fromType.GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (var prop in props) { var name = prop.Name; var type = prop.PropertyType; var subPath = path.Append(name); var value = prop.GetValue(fromValue); if (value == null) { continue; } context.Serialize(subPath, value, type, options); } }
public void Serialize(MapPath path, object fromValue, Type fromType, IMapSerializeOptions options, IMapSerializeContext context) { if (fromType == null) { throw new ArgumentNullException(nameof(fromType)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } var converter = this._converters.FirstOrDefault(x => x.CanSerialize(path, fromValue, fromType, options, context)); if (converter == null) { throw new InvalidOperationException($"无法找到转换器。[value: {fromValue}][type: {fromType}]"); } converter.Serialize(path, fromValue, fromType, options, context); }
public IMapTable AfterSerialize(IMapSerializeOptions options) { if (options == null) { throw new ArgumentNullException(nameof(options)); } var table = new MapTable(this); var maps = options.GetMaps(); foreach (var map in maps) { var token = table.GetToken(map.Key); table.Remove(map.Key); foreach (var path in map.Value) { table.SetToken(path, token); } } return(table); }
public void Serialize(MapPath path, object fromValue, Type fromType, IMapSerializeOptions options, IMapSerializeContext context) { context.Table.AddToken(path, new MapTimeSpanToken((TimeSpan)fromValue)); }
public bool CanSerialize(MapPath path, object fromValue, Type fromType, IMapSerializeOptions options, IMapSerializeContext context) { return(fromType.Equals <TimeSpan>()); }
public bool CanSerialize(MapPath path, object fromValue, Type fromType, IMapSerializeOptions options, IMapSerializeContext context) { return(ArrayUtil.Check(fromType)); }
public void Serialize(MapPath path, object fromValue, Type fromType, IMapSerializeOptions options, IMapSerializeContext context) { if (fromType.Equals <Single>()) { context.Table.AddToken(path, new MapSingleToken((Single)fromValue)); return; } if (fromType.Equals <Double>()) { context.Table.AddToken(path, new MapDoubleToken((Double)fromValue)); return; } if (fromType.Equals <Decimal>()) { context.Table.AddToken(path, new MapDecimalToken((Decimal)fromValue)); return; } if (fromType.Equals <SByte>()) { context.Table.AddToken(path, new MapInt8Token((SByte)fromValue)); return; } if (fromType.Equals <Int16>()) { context.Table.AddToken(path, new MapInt16Token((Int16)fromValue)); return; } if (fromType.Equals <Int32>()) { context.Table.AddToken(path, new MapInt32Token((Int32)fromValue)); return; } if (fromType.Equals <Int64>()) { context.Table.AddToken(path, new MapInt64Token((Int64)fromValue)); return; } if (fromType.Equals <Byte>()) { context.Table.AddToken(path, new MapUInt8Token((Byte)fromValue)); return; } if (fromType.Equals <UInt16>()) { context.Table.AddToken(path, new MapUInt16Token((UInt16)fromValue)); return; } if (fromType.Equals <UInt32>()) { context.Table.AddToken(path, new MapUInt32Token((UInt32)fromValue)); return; } if (fromType.Equals <UInt64>()) { context.Table.AddToken(path, new MapUInt64Token((UInt64)fromValue)); return; } throw new NotImplementedException(); }
public bool CanSerialize(MapPath path, object fromValue, Type fromType, IMapSerializeOptions options, IMapSerializeContext context) { return(fromType.IsEnum); }
public void Serialize(MapPath path, object fromValue, Type fromType, IMapSerializeOptions options, IMapSerializeContext context) { context.Table.AddToken(path, new MapEnumToken(fromValue, fromType)); }
public bool CanSerialize(MapPath path, object fromValue, Type fromType, IMapSerializeOptions options, IMapSerializeContext context) { return(TYPES.Any(x => x.Equals(fromType))); }