Skip to content

Commit e252ea6

Browse files
authored
Optimize BsonUtils.ToHexString on .NET 5.0+ (#1450)
1 parent bd90b3e commit e252ea6

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/MongoDB.Bson/BsonUtils.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,13 @@ public static char ToHexChar(int value)
117117
/// <returns>A hex string.</returns>
118118
public static string ToHexString(byte[] bytes)
119119
{
120+
#if NET5_0_OR_GREATER
121+
ArgumentNullException.ThrowIfNull(bytes);
122+
return Convert.ToHexString(bytes).ToLowerInvariant();
123+
#else
120124
if (bytes == null)
121125
{
122-
throw new ArgumentNullException("bytes");
126+
throw new ArgumentNullException(nameof(bytes));
123127
}
124128

125129
var length = bytes.Length;
@@ -133,6 +137,7 @@ public static string ToHexString(byte[] bytes)
133137
}
134138

135139
return new string(c);
140+
#endif
136141
}
137142

138143
/// <summary>

0 commit comments

Comments
 (0)