Skip to content

Commit 8b426ba

Browse files
committed
为 TextSerializationOptions 类的 Converters 属性添加详细的 XML 范例说明。 🐂
1 parent 37fcb21 commit 8b426ba

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

Zongsoft.Core/src/Serialization/TextSerializationOptionsBuilder.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Authors:
1010
* 钟峰(Popeye Zhong) <zongsoft@qq.com>
1111
*
12-
* Copyright (C) 2010-2024 Zongsoft Studio <http://www.zongsoft.com>
12+
* Copyright (C) 2010-2026 Zongsoft Studio <http://www.zongsoft.com>
1313
*
1414
* This file is part of Zongsoft.Core library.
1515
*
@@ -57,6 +57,40 @@ public TextSerializationOptionsBuilder(params IEnumerable<object> converters)
5757

5858
#region 公共属性
5959
public TextSerializationOptions Default => TextSerializationOptions.Default;
60+
61+
/// <summary>获取文本序列化的全局转换器列表。</summary>
62+
/// <example>
63+
/// <code>
64+
/// <![CDATA[
65+
/// public class VersionConverter : JsonConverter<SemanticVersion>
66+
/// {
67+
/// public override SemanticVersion Read(ref Utf8JsonReader reader, Type type, JsonSerializerOptions options) => reader.TokenType switch
68+
/// {
69+
/// JsonTokenType.Null => null,
70+
/// JsonTokenType.String => SemanticVersion.Parse(reader.GetString()),
71+
/// _ => throw new JsonException(),
72+
/// };
73+
///
74+
/// public override void Write(Utf8JsonWriter writer, SemanticVersion value, JsonSerializerOptions options)
75+
/// {
76+
/// if(value == null)
77+
/// writer.WriteNullValue();
78+
/// else
79+
/// writer.WriteStringValue(value.ToFullString());
80+
/// }
81+
///
82+
/// [Service<IApplicationInitializer>]
83+
/// public sealed class Initializer : IApplicationInitializer
84+
/// {
85+
/// public void Initialize(IApplicationContext context)
86+
/// {
87+
/// Zongsoft.Serialization.Serializer.Json.Options.Converters.Add(new VersionConverter());
88+
/// }
89+
/// }
90+
/// }
91+
/// ]]>
92+
/// </code>
93+
/// </example>
6094
public IList<object> Converters { get; }
6195
#endregion
6296

0 commit comments

Comments
 (0)