public override void Reference(SerializeOption other) { base.Reference(other); Format = ((JsonSerializeOption)other).Format; IgnoreNull = ((JsonSerializeOption)other).IgnoreNull; }
/// <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)); }
/// <summary> /// 引用另一个对象的设置属性。 /// </summary> /// <param name="other"></param> public override void Reference(SerializeOption other) { base.Reference(other); if (other is JsonSerializeOption joption) { KeyHandling = joption.KeyHandling; } }
/// <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); }
/// <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; } }
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; }
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() },
/// <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; } }
/// <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); } }
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()); } }
/// <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); } }
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);
public string Serialize(PortableProperty property, string ns, SerializeOption option) => Base(property, ns, option);
public string Serialize(PortableProperty property, string prefix, SerializeOption option) => Base(property, prefix, option);