예제 #1
0
        private static void HandleError(int result)
        {
            string   errorMessage;
            GitError error     = null;
            var      errHandle = NativeMethods.giterr_last();

            if (errHandle != null && !errHandle.IsInvalid)
            {
                error = errHandle.MarshalAsGitError();
            }

            if (error == null)
            {
                error = new GitError {
                    Category = GitErrorCategory.Unknown, Message = IntPtr.Zero
                };
                errorMessage = "No error message has been provided by the native library";
            }
            else
            {
                errorMessage = LaxUtf8Marshaler.FromNative(error.Message);
            }

            Func <string, GitErrorCode, GitErrorCategory, LibGit2SharpException> exceptionBuilder;

            if (!GitErrorsToLibGit2SharpExceptions.TryGetValue((GitErrorCode)result, out exceptionBuilder))
            {
                exceptionBuilder = (m, r, c) => new LibGit2SharpException(m, r, c);
            }

            throw exceptionBuilder(errorMessage, (GitErrorCode)result, error.Category);
        }
예제 #2
0
        /// <summary>
        /// Enumerates each string from the array using the UTF-8 marshaler.
        /// </summary>
        public             String[] ReadStrings()
        {
            var count = checked ((int)Array.Count.ToUInt32());

            String[] toReturn = new String[count];

            for (int i = 0; i < count; i++)
            {
                toReturn[i] = LaxUtf8Marshaler.FromNative(Marshal.ReadIntPtr(Array.Strings, i * IntPtr.Size));
            }

            return(toReturn);
        }
예제 #3
0
        private static unsafe void HandleError(int result)
        {
            string           errorMessage;
            GitErrorCategory errorCategory = GitErrorCategory.Unknown;
            GitError *       error         = NativeMethods.giterr_last();

            if (error == null)
            {
                errorMessage = "No error message has been provided by the native library";
            }
            else
            {
                errorMessage = LaxUtf8Marshaler.FromNative(error->Message);
            }

            Func <string, GitErrorCode, GitErrorCategory, LibGit2SharpException> exceptionBuilder;

            if (!GitErrorsToLibGit2SharpExceptions.TryGetValue((GitErrorCode)result, out exceptionBuilder))
            {
                exceptionBuilder = (m, r, c) => new LibGit2SharpException(m, r, c);
            }

            throw exceptionBuilder(errorMessage, (GitErrorCode)result, errorCategory);
        }
예제 #4
0
 public new static FilePath FromBuffer(byte[] buffer)
 {
     return(LaxUtf8Marshaler.FromBuffer(buffer));
 }
예제 #5
0
 public new static unsafe FilePath FromNative(char *buffer)
 {
     return(LaxUtf8Marshaler.FromNative(buffer));
 }
예제 #6
0
 public new static FilePath FromNative(IntPtr pNativeData)
 {
     return(LaxUtf8Marshaler.FromNative(pNativeData));
 }