跳到导航

2.19.0

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

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

// Creating union values
var response = MyUnion.FromString("hello");
var response = MyUnion.FromInt(42);
var response = MyUnion.FromCustomObject(new CustomObject { ... });
// Type-safe value access with Is* properties and As* methods
if (response.IsString)
{
string value = response.AsString();
Console.WriteLine($"Got string: {value}");
}
else if (response.IsInt)
{
int value = response.AsInt();
Console.WriteLine($"Got integer: {value}");
}
// Safe extraction with TryAs* pattern (no exceptions)
if (response.TryAsCustomObject(out var obj))
{
Console.WriteLine($"Got object: {obj.Name}");
}

与使用通用 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.