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 bool IsIgnore(MapPath path) { if (path == null) { throw new ArgumentNullException(nameof(path)); } return(this._ignores.Any(p => p.Equals(path))); }
public IMapSerializeOptions Map(MapPath from, params MapPath[] to) { if (from == null) { throw new ArgumentNullException(nameof(from)); } return(this.Map(from, to.AsEnumerable())); }
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 IMapSerializeOptions Ignore(MapPath path) { if (path == null) { throw new ArgumentNullException(nameof(path)); } this._ignores.Add(path); return(this); }
public object Deserialize(MapPath path, Type toType, IMapDeserializeOptions options) { //! ignore path; if (options.IsIgnore(path)) { return(null); } return(this._deserializer.Deserialize(path, toType, options, this)); }
public bool CanDeserialize(MapPath path, Type toType, IMapDeserializeOptions options, IMapDeserializeContext context) { var token = context.Table.GetToken(path); if (!(token is MapNullToken)) { return(false); } return((!toType.IsValueType) || (toType.IsValueType && toType.IsNullable())); }
public object Deserialize(MapPath path, Type toType, IMapDeserializeOptions options, IMapDeserializeContext context) { var converter = this._converters.FirstOrDefault(x => x.CanDeserialize(path, toType, options, context)); if (converter == null) { throw new InvalidOperationException($"无法找到转换器。[node: {path}][type: {toType}]"); } return(converter.Deserialize(path, toType, options, context)); }
public bool CanDeserialize(MapPath path, Type toType, IMapDeserializeOptions options, IMapDeserializeContext context) { var token = context.Table.GetToken(path); if (!(token is MapEnumToken)) { return(false); } return(token.Compatible(toType)); }
public bool CanDeserialize(MapPath path, Type toType, IMapDeserializeOptions options, IMapDeserializeContext context) { var token = context.Table.GetToken(path); if (!(token is MapArrayToken)) { return(false); } return(ArrayUtil.Check(toType)); }
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 object Deserialize(MapPath path, Type toType, IMapDeserializeOptions options, IMapDeserializeContext context) { var obj = Activator.CreateInstance(toType); var children = context.Table.GetChildren(path).ToList(); foreach (var child in children) { var name = child.Key.LastSegment(); var prop = toType.GetProperty(name); var type = prop.PropertyType; var value = context.Deserialize(child.Key, type, options); prop.SetValue(obj, value); } return(obj); }
public object Deserialize(MapPath path, Type toType, IMapDeserializeOptions options, IMapDeserializeContext context) { var children = context.Table.GetChildren(path); var elemType = ArrayUtil.GetElementType(toType); var arr = Array.CreateInstance(elemType, children.Count()); foreach (var child in children) { var value = context.Deserialize(child.Key, elemType, options); ArrayUtil.SetValue(arr, int.Parse(child.Key.LastSegment()), value); } if (ArrayUtil.IsArray(toType)) { return(arr); } return(ArrayUtil.ToList(elemType, arr)); }
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) { 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) { 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 IMapSerializeOptions Map(MapPath from, IEnumerable <MapPath> to) { if (from == null) { throw new ArgumentNullException(nameof(from)); } if (to == null) { throw new ArgumentNullException(nameof(to)); } if (this._maps.ContainsKey(from)) { this._maps[from].AddRange(to); } else { this._maps.Add(from, new List <MapPath>(to)); } return(this); }
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(fromType.IsEnum); }
public object Deserialize(MapPath path, Type toType, IMapDeserializeOptions options, IMapDeserializeContext context) { return(context.Table.GetToken(path).GetValue(toType)); }
public bool CanDeserialize(MapPath path, Type toType, IMapDeserializeOptions options, IMapDeserializeContext context) { return(toType.IsNullable()); }
public object Deserialize(MapPath path, Type toType, IMapDeserializeOptions options, IMapDeserializeContext context) { var innerType = toType.GetGenericArguments()[0]; return(context.Deserialize(path, innerType, options)); }
public bool CanSerialize(MapPath path, object fromValue, Type fromType, IMapSerializeOptions options, IMapSerializeContext context) { return(TYPES.Any(x => x.Equals(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 static IMapperBuilder Ignore <T>(this IMapperBuilder builder, Expression <Func <T, object> > field) { return(builder.Ignore(typeof(T), MapPath.Parse(field))); }
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 object Deserialize(MapPath path, Type toType, IMapDeserializeOptions options, IMapDeserializeContext context) { return(null); }