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);
        }
Ejemplo n.º 2
0
        public bool IsIgnore(MapPath path)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            return(this._ignores.Any(p => p.Equals(path)));
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 5
0
        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));
        }
Ejemplo n.º 7
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.º 8
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.º 9
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.º 10
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.º 11
0
        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);
        }
Ejemplo n.º 12
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.º 13
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.º 14
0
        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);
            }
        }
Ejemplo n.º 15
0
        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);
            }
        }
Ejemplo n.º 16
0
        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);
        }
Ejemplo n.º 17
0
        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);
        }
Ejemplo n.º 18
0
 public void Serialize(MapPath path, object fromValue, Type fromType, IMapSerializeOptions options, IMapSerializeContext context)
 {
     context.Table.AddToken(path, new MapEnumToken(fromValue, fromType));
 }
Ejemplo n.º 19
0
 public bool CanSerialize(MapPath path, object fromValue, Type fromType, IMapSerializeOptions options, IMapSerializeContext context)
 {
     return(fromType.IsEnum);
 }
Ejemplo n.º 20
0
 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));
        }
Ejemplo n.º 23
0
 public bool CanSerialize(MapPath path, object fromValue, Type fromType, IMapSerializeOptions options, IMapSerializeContext context)
 {
     return(TYPES.Any(x => x.Equals(fromType)));
 }
Ejemplo n.º 24
0
        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();
        }
Ejemplo n.º 25
0
 public static IMapperBuilder Ignore <T>(this IMapperBuilder builder, Expression <Func <T, object> > field)
 {
     return(builder.Ignore(typeof(T), MapPath.Parse(field)));
 }
Ejemplo n.º 26
0
 public void Serialize(MapPath path, object fromValue, Type fromType, IMapSerializeOptions options, IMapSerializeContext context)
 {
     context.Table.AddToken(path, new MapTimeSpanToken((TimeSpan)fromValue));
 }
Ejemplo n.º 27
0
 public bool CanSerialize(MapPath path, object fromValue, Type fromType, IMapSerializeOptions options, IMapSerializeContext context)
 {
     return(fromType.Equals <TimeSpan>());
 }
Ejemplo n.º 28
0
 public bool CanSerialize(MapPath path, object fromValue, Type fromType, IMapSerializeOptions options, IMapSerializeContext context)
 {
     return(ArrayUtil.Check(fromType));
 }
Ejemplo n.º 29
0
 public object Deserialize(MapPath path, Type toType, IMapDeserializeOptions options, IMapDeserializeContext context)
 {
     return(null);
 }