|
9 | 9 | * Authors: |
10 | 10 | * 钟峰(Popeye Zhong) <zongsoft@qq.com> |
11 | 11 | * |
12 | | - * Copyright (C) 2010-2024 Zongsoft Studio <http://www.zongsoft.com> |
| 12 | + * Copyright (C) 2010-2026 Zongsoft Studio <http://www.zongsoft.com> |
13 | 13 | * |
14 | 14 | * This file is part of Zongsoft.Core library. |
15 | 15 | * |
@@ -57,6 +57,40 @@ public TextSerializationOptionsBuilder(params IEnumerable<object> converters) |
57 | 57 |
|
58 | 58 | #region 公共属性 |
59 | 59 | 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> |
60 | 94 | public IList<object> Converters { get; } |
61 | 95 | #endregion |
62 | 96 |
|
|
0 commit comments