Skip to content
This repository was archived by the owner on Jan 25, 2026. It is now read-only.

Commit 4540a9d

Browse files
committed
fix(ArgumentsBuilder): null 检查
1 parent 39db188 commit 4540a9d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Utils/ArgumentsBuilder.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23
using System.Text;
34

@@ -9,7 +10,7 @@ namespace PCL.Core.Utils;
910

1011
public class ArgumentsBuilder
1112
{
12-
private readonly Dictionary<string, string> _args = new();
13+
private readonly Dictionary<string, string?> _args = new();
1314

1415
/// <summary>
1516
/// 添加键值对参数(自动处理空格转义)
@@ -18,6 +19,8 @@ public class ArgumentsBuilder
1819
/// <param name="value">参数值</param>
1920
public ArgumentsBuilder Add(string key, string value)
2021
{
22+
if (key is null) throw new NullReferenceException(nameof(key));
23+
if (value is null) throw new NullReferenceException(nameof(value));
2124
_args[key] = _handleEscapeValue(value);
2225
return this;
2326
}
@@ -28,6 +31,7 @@ public ArgumentsBuilder Add(string key, string value)
2831
/// <param name="flag">标志名(不带前缀)</param>
2932
public ArgumentsBuilder AddFlag(string flag)
3033
{
34+
if (flag is null) throw new NullReferenceException(nameof(flag));
3135
_args[flag] = null;
3236
return this;
3337
}
@@ -77,7 +81,7 @@ public string Build(int prefixStyle = 0)
7781
}
7882

7983
// 添加值(如果有)
80-
if (arg.Value != null)
84+
if (arg.Value is not null)
8185
{
8286
sb.Append('=').Append(arg.Value);
8387
}

0 commit comments

Comments
 (0)