Skip to content

Commit 7ea126f

Browse files
jamillnulltoken
authored andcommitted
Introduce helper method to cope with UIntPtr to int conversion
1 parent b304c07 commit 7ea126f

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

LibGit2Sharp/Core/Proxy.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3461,5 +3461,28 @@ internal static int ConvertResultToCancelFlag(bool result)
34613461
return result ? 0 : (int)GitErrorCode.User;
34623462
}
34633463
}
3464+
3465+
/// <summary>
3466+
/// Class to hold extension methods used by the proxy class.
3467+
/// </summary>
3468+
static class ProxyExtensions
3469+
{
3470+
/// <summary>
3471+
/// Convert a UIntPtr to a int value. Will throw
3472+
/// exception if there is an overflow.
3473+
/// </summary>
3474+
/// <param name="input"></param>
3475+
/// <returns></returns>
3476+
public static int ConvertToInt(this UIntPtr input)
3477+
{
3478+
ulong ulongValue = (ulong)input;
3479+
if (ulongValue > int.MaxValue)
3480+
{
3481+
throw new LibGit2SharpException("value exceeds size of an int");
3482+
}
3483+
3484+
return (int)input;
3485+
}
3486+
}
34643487
}
34653488
// ReSharper restore InconsistentNaming

0 commit comments

Comments
 (0)