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));
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 5
0
        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()));
        }
Ejemplo n.º 6
0
        public object To(Type toType, IMapDeserializeOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            this._config.AttachTo(toType, options);
            var context = new MapDeserializeContext(this._deserializer, this._table.BeforeDeserialize(options));

            return(this._deserializer.Deserialize(MapPath.Root, toType, options, context));
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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));
        }
Ejemplo n.º 9
0
        public IMapTable BeforeDeserialize(IMapDeserializeOptions 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);
        }
Ejemplo n.º 10
0
 public object Deserialize(MapPath path, Type toType, IMapDeserializeOptions options, IMapDeserializeContext context)
 {
     return(context.Table.GetToken(path).GetValue(toType));
 }
Ejemplo n.º 11
0
 public object Deserialize(MapPath path, Type toType, IMapDeserializeOptions options, IMapDeserializeContext context)
 {
     return(null);
 }
        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());
 }