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);
        }
예제 #3
0
        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));
        }
예제 #4
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);
        }
예제 #5
0
        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));
        }
예제 #6
0
        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));
        }
예제 #7
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);
            }
        }
예제 #8
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);
            }
        }
예제 #9
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);
        }
예제 #10
0
        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);
        }
예제 #11
0
 public void Serialize(MapPath path, object fromValue, Type fromType, IMapSerializeOptions options, IMapSerializeContext context)
 {
     context.Table.AddToken(path, new MapTimeSpanToken((TimeSpan)fromValue));
 }
예제 #12
0
 public bool CanSerialize(MapPath path, object fromValue, Type fromType, IMapSerializeOptions options, IMapSerializeContext context)
 {
     return(fromType.Equals <TimeSpan>());
 }
예제 #13
0
 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();
        }
예제 #15
0
 public bool CanSerialize(MapPath path, object fromValue, Type fromType, IMapSerializeOptions options, IMapSerializeContext context)
 {
     return(fromType.IsEnum);
 }
예제 #16
0
 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)));
 }