diff --git a/LibGit2Sharp/Core/Ensure.cs b/LibGit2Sharp/Core/Ensure.cs index 5e7ea30b3..ceb3dd8a1 100644 --- a/LibGit2Sharp/Core/Ensure.cs +++ b/LibGit2Sharp/Core/Ensure.cs @@ -35,7 +35,7 @@ public static void ArgumentNotNullOrEmptyEnumerable(IEnumerable argumentVa { ArgumentNotNull(argumentValue, argumentName); - if (argumentValue.Count() == 0) + if (!argumentValue.Any()) { throw new ArgumentException("Enumerable cannot be empty", argumentName); } @@ -50,7 +50,7 @@ public static void ArgumentNotNullOrEmptyString(string argumentValue, string arg { ArgumentNotNull(argumentValue, argumentName); - if (argumentValue.Trim().Length == 0) + if (String.IsNullOrWhiteSpace (argumentValue)) { throw new ArgumentException("String cannot be empty", argumentName); } @@ -145,17 +145,15 @@ public static void ZeroResult(int result) } /// - /// Check that the result of a C call that returns a boolean value - /// was successful + /// Check that the result of a C call returns a boolean value. /// - /// The native function is expected to return strictly 0 for - /// success or a negative value in the case of failure. + /// The native function is expected to return strictly 0 or 1. /// /// /// The result to examine. public static void BooleanResult(int result) { - if (result == (int)GitErrorCode.Ok || result == 1) + if (result == 0 || result == 1) { return; } @@ -164,11 +162,11 @@ public static void BooleanResult(int result) } /// - /// Check that the result of a C call that returns an integer value - /// was successful + /// Check that the result of a C call that returns an integer + /// value was successful. /// - /// The native function is expected to return strictly 0 for - /// success or a negative value in the case of failure. + /// The native function is expected to return 0 or a positive + /// value for success or a negative value in the case of failure. /// /// /// The result to examine. @@ -182,16 +180,6 @@ public static void Int32Result(int result) HandleError(result); } - public static void NotNullResult(Object result) - { - if (result != null) - { - return; - } - - HandleError((int)GitErrorCode.Error); - } - /// /// Checks an argument by applying provided checker. /// @@ -208,6 +196,15 @@ public static void ArgumentConformsTo(T argumentValue, Func checker, throw new ArgumentException(argumentName); } + /// + /// Check that the result of a C call that returns a non-null GitObject + /// using the default exception builder. + /// + /// The native function is expected to return a valid object value. + /// + /// + /// The to examine. + /// The identifier to examine. public static void GitObjectIsNotNull(GitObject gitObject, string identifier) { Func exceptionBuilder; @@ -224,6 +221,17 @@ public static void GitObjectIsNotNull(GitObject gitObject, string identifier) GitObjectIsNotNull(gitObject, identifier, exceptionBuilder); } + + /// + /// Check that the result of a C call that returns a non-null GitObject + /// using the default exception builder. + /// + /// The native function is expected to return a valid object value. + /// + /// + /// The to examine. + /// The identifier to examine. + /// The builder which constructs an from a message. public static void GitObjectIsNotNull( GitObject gitObject, string identifier,