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);
        }
Example #2
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);
            }
        }
Example #3
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);
            }
        }