2.19.0

(feat): 通过新的 use-undiscriminated-unions 配置选项添加对类型安全的无区分联合类型的支持。

无区分联合类型提供了一种干净、类型安全的方式来处理可能是多种类型之一的值:

1// Creating union values
2var response = MyUnion.FromString("hello");
3var response = MyUnion.FromInt(42);
4var response = MyUnion.FromCustomObject(new CustomObject { ... });
5
6// Type-safe value access with Is* properties and As* methods
7if (response.IsString)
8{
9 string value = response.AsString();
10 Console.WriteLine($"Got string: {value}");
11}
12else if (response.IsInt)
13{
14 int value = response.AsInt();
15 Console.WriteLine($"Got integer: {value}");
16}
17
18// Safe extraction with TryAs* pattern (no exceptions)
19if (response.TryAsCustomObject(out var obj))
20{
21 Console.WriteLine($"Got object: {obj.Name}");
22}

与使用通用 object 类型相比,这提供了更好的 IntelliSense 支持和编译时安全性。

(chore): 减少 NuGet 包依赖项。当不使用无区分联合类型时,不再需要 OneOf 库,从而减少了包大小和传递依赖项数量。

2.18.1

(fix): 虽然大多数 <> 应该被转义为 &lt;&gt; 以避免输出内容损坏,但真正的 XML/HTML 标签应该保持原样;此提交扫描潜在的有效标签并防止它们被转义。(有歧义的情况会被转义。)

修复前:

/// XMLDoc (C#) (Example of actual XML tags):
/// See &lt;a href="https://example.com/docs"&gt;the docs&lt;/a&gt; for more info.
/// Use &lt;code&gt;getValue()&lt;/code&gt; to retrieve the value.
/// Note: when count &lt; 10 or count &gt; 100, special handling applies.

修复后:

/// XMLDoc (C#) (Example of actual XML tags):
/// See <a href="https://example.com/docs">the docs</a> for more info.
/// Use <code>getValue()</code> to retrieve the value.
/// Note: when count &lt; 10 or count &gt; 100, special handling applies.