change throw to return and fix bug: when error always throw

This commit is contained in:
2025-04-23 13:41:48 +08:00
parent 87c158ebfe
commit 0fb5a16b8e
6 changed files with 169 additions and 122 deletions

View File

@@ -18,10 +18,10 @@ namespace Common
{
if (length > 8)
{
throw new ArgumentException(
return new(new ArgumentException(
"Unsigned long number can't over 8 bytes(64 bits).",
nameof(length)
);
));
}
var arr = new byte[length];
@@ -53,10 +53,10 @@ namespace Common
{
if (bytes.Length > 8)
{
throw new ArgumentException(
return new(new ArgumentException(
"Unsigned long number can't over 8 bytes(64 bits).",
nameof(bytes)
);
));
}
ulong num = 0;
@@ -106,7 +106,7 @@ namespace Common
/// <returns>[TODO:return]</returns>
public static Result<ulong> MultiBitsToNumber(ulong bits1, uint bits1Len, ulong bits2, uint bits2Len)
{
if (bits1Len + bits2Len > 64) throw new ArgumentException("Two Bits is more than 64 bits");
if (bits1Len + bits2Len > 64) return new(new ArgumentException("Two Bits is more than 64 bits"));
ulong num = (bits1 << Convert.ToInt32(bits2Len)) | bits2;
return num;
@@ -122,7 +122,7 @@ namespace Common
/// <returns>[TODO:return]</returns>
public static Result<uint> MultiBitsToNumber(uint bits1, uint bits1Len, uint bits2, uint bits2Len)
{
if (bits1Len + bits2Len > 64) throw new ArgumentException("Two Bits is more than 64 bits");
if (bits1Len + bits2Len > 64) return new(new ArgumentException("Two Bits is more than 64 bits"));
uint num = (bits1 << Convert.ToInt32(bits2Len)) | bits2;
return num;