Inheritance: ICustomMarshaler
Exemplo n.º 1
0
        private static void HandleError(int result)
        {
            string   errorMessage;
            GitError error = NativeMethods.giterr_last().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 = Utf8Marshaler.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);
        }
Exemplo n.º 2
0
        public static ICustomMarshaler GetInstance(string cookie)
        {
            if (staticInstance == null)
            {
                return staticInstance = new Utf8Marshaler();
            }

            return staticInstance;
        }
Exemplo n.º 3
0
        public static FilePath FromNative(IntPtr pNativeData, int length)
        {
            if (0 == length)
            {
                return(FilePath.Empty);
            }

            return(Utf8Marshaler.FromNative(pNativeData, length));
        }
Exemplo n.º 4
0
        public static IntPtr FromManaged(FilePath filePath)
        {
            if (null == filePath)
            {
                return(IntPtr.Zero);
            }

            return(Utf8Marshaler.FromManaged(filePath.Posix));
        }
Exemplo n.º 5
0
        public static ICustomMarshaler GetInstance(string cookie)
        {
            if (staticInstance == null)
            {
                return(staticInstance = new Utf8Marshaler());
            }

            return(staticInstance);
        }
Exemplo n.º 6
0
        public static FilePath FromNative(IntPtr pNativeData)
        {
            if (IntPtr.Zero == pNativeData)
            {
                return(null);
            }

            if (0 == Marshal.ReadByte(pNativeData))
            {
                return(FilePath.Empty);
            }

            return(Utf8Marshaler.FromNative(pNativeData));
        }
Exemplo n.º 7
0
        private static void HandleError(int result)
        {
            string   errorMessage;
            GitError error = NativeMethods.giterr_last().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 = Utf8Marshaler.FromNative(error.Message);
            }

            switch (result)
            {
            case (int)GitErrorCode.User:
                throw new UserCancelledException(errorMessage, (GitErrorCode)result, error.Category);

            case (int)GitErrorCode.BareRepo:
                throw new BareRepositoryException(errorMessage, (GitErrorCode)result, error.Category);

            case (int)GitErrorCode.Exists:
                throw new NameConflictException(errorMessage, (GitErrorCode)result, error.Category);

            case (int)GitErrorCode.InvalidSpecification:
                throw new InvalidSpecificationException(errorMessage, (GitErrorCode)result, error.Category);

            case (int)GitErrorCode.UnmergedEntries:
                throw new UnmergedIndexEntriesException(errorMessage, (GitErrorCode)result, error.Category);

            case (int)GitErrorCode.NonFastForward:
                throw new NonFastForwardException(errorMessage, (GitErrorCode)result, error.Category);

            case (int)GitErrorCode.MergeConflict:
                throw new MergeConflictException(errorMessage, (GitErrorCode)result, error.Category);

            default:
                throw new LibGit2SharpException(errorMessage, (GitErrorCode)result, error.Category);
            }
        }