コード例 #1
0
        public override void Reference(SerializeOption other)
        {
            base.Reference(other);

            Format     = ((JsonSerializeOption)other).Format;
            IgnoreNull = ((JsonSerializeOption)other).IgnoreNull;
        }
コード例 #2
0
        /// <summary>
        /// Serialize to string
        /// </summary>
        /// <param name="serializer"></param>
        /// <param name="o"></param>
        /// <param name="format"></param>
        public static string SerializeToString(this ISerializer serializer,
                                               object o, SerializeOption format = SerializeOption.None)
        {
            var span = serializer.SerializeToBytes(o, format);

            return(serializer.ContentEncoding?.GetString(span)
                   ?? Convert.ToBase64String(span));
        }
コード例 #3
0
        /// <summary>
        /// 引用另一个对象的设置属性。
        /// </summary>
        /// <param name="other"></param>
        public override void Reference(SerializeOption other)
        {
            base.Reference(other);

            if (other is JsonSerializeOption joption)
            {
                KeyHandling = joption.KeyHandling;
            }
        }
コード例 #4
0
        /// <summary>
        /// Serialize to byte array
        /// </summary>
        /// <param name="serializer"></param>
        /// <param name="o"></param>
        /// <param name="format"></param>
        public static ReadOnlySpan <byte> SerializeToBytes(
            this ISerializer serializer, object o,
            SerializeOption format = SerializeOption.None)
        {
            var writer = new ArrayBufferWriter <byte>();

            serializer.Serialize(writer, o, format);
            return(writer.WrittenSpan);
        }
コード例 #5
0
        /// <summary>
        /// 引用另一个对象的设置属性。
        /// </summary>
        /// <param name="other"></param>
        public override void Reference(SerializeOption other)
        {
            base.Reference(other);

            if (other is JsonSerializeOption joption)
            {
                Format     = joption.Format;
                IgnoreNull = joption.IgnoreNull;
            }
        }
コード例 #6
0
ファイル: XmlSerializeOption.cs プロジェクト: indiff/fireasy2
        public override void Reference(SerializeOption other)
        {
            base.Reference(other);

            CData        = ((XmlSerializeOption)other).CData;
            Declaration  = ((XmlSerializeOption)other).Declaration;
            StartElement = ((XmlSerializeOption)other).StartElement;
            IgnoreNull   = ((XmlSerializeOption)other).IgnoreNull;
            OutputStyle  = ((XmlSerializeOption)other).OutputStyle;
        }
コード例 #7
0
 private string Base(PortableProperty property, string ns, SerializeOption option)
 {
     return(property.HasForeignKey switch
     {
         true => option switch
         {
             SerializeOption.ColumnsSub => ColumnsSub(property, ns),
             SerializeOption.ColumnsUnion => ColumnsUnion(property, ns),
             SerializeOption.LeftJoinsUnion => LeftJoinsUnion(property, ns),
             _ => throw new InvalidEnumArgumentException()
         },
コード例 #8
0
        /// <summary>
        /// 引用另一个对象的设置属性。
        /// </summary>
        /// <param name="other"></param>
        public override void Reference(SerializeOption other)
        {
            base.Reference(other);

            if (other is XmlSerializeOption xoption)
            {
                CData        = xoption.CData;
                Declaration  = xoption.Declaration;
                StartElement = xoption.StartElement;
                IgnoreNull   = xoption.IgnoreNull;
                NodeStyle    = xoption.NodeStyle;
            }
        }
コード例 #9
0
        /// <inheritdoc/>
        public void Serialize(IBufferWriter <byte> buffer, object o, SerializeOption format)
        {
            try {
#if MessagePack2
                MsgPack.Serialize(buffer, o, Options);
#else
                var b = MsgPack.Serialize(o?.GetType() ?? typeof(object), o, Options);
                buffer.Write(b);
#endif
            }
            catch (MessagePackSerializationException ex) {
                throw new SerializerException(ex.Message, ex);
            }
        }
コード例 #10
0
        public static string Serialize(object obj, SerializeOption serializeOption = SerializeOption.Short)
        {
            var serializer = new Newtonsoft.Json.JsonSerializer
            {
                NullValueHandling = NullValueHandling.Include,
                Formatting        = serializeOption == SerializeOption.Short ? Formatting.None : Formatting.Indented,
            };
            var sb = new StringBuilder();

            using (var sw = new StringWriter(sb))
                using (JsonWriter writer = new JsonTextWriter(sw))
                {
                    serializer.Serialize(writer, obj);
                    return(sb.ToString());
                }
        }
コード例 #11
0
 /// <inheritdoc/>
 public void Serialize(IBufferWriter <byte> buffer, object o, SerializeOption format)
 {
     try {
         var jsonSerializer = JsonSerializer.CreateDefault(Settings);
         jsonSerializer.Formatting = format == SerializeOption.Indented ?
                                     Formatting.Indented :
                                     Formatting.None;
         // TODO move to .net 3 to use buffer writer as stream sink
         using (var stream = new MemoryStream()) {
             using (var writer = new StreamWriter(stream)) {
                 jsonSerializer.Serialize(writer, o);
             }
             var written = stream.ToArray();
             buffer.Write(written);
         }
     }
     catch (JsonReaderException ex) {
         throw new SerializerException(ex.Message, ex);
     }
 }
コード例 #12
0
 private static string Properties(PortableType type, string ns, SerializeOption option, Func <PortableProperty, string, SerializeOption, string> serialize) => type.Properties.Select(i => serialize(i, ns, option)).Aggregate(string.Empty, (current, i) => current + i);
コード例 #13
0
 public string Serialize(PortableProperty property, string ns, SerializeOption option) => Base(property, ns, option);
コード例 #14
0
 public string Serialize(PortableProperty property, string prefix, SerializeOption option) =>
 Base(property, prefix, option);