public object Deserialize(MapPath path, Type toType, IMapDeserializeOptions options, IMapDeserializeContext context) { return(context.Table.GetToken(path).GetValue(toType)); }
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 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 object Deserialize(MapPath path, Type toType, IMapDeserializeOptions options, IMapDeserializeContext context) { return(null); }
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 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 innerType = toType.GetGenericArguments()[0]; return(context.Deserialize(path, innerType, options)); }
public bool CanDeserialize(MapPath path, Type toType, IMapDeserializeOptions options, IMapDeserializeContext context) { return(toType.IsNullable()); }