MarshalNativeToManaged() public method

public MarshalNativeToManaged ( IntPtr pNativeData ) : object
pNativeData System.IntPtr
return object
示例#1
0
        /// <summary>
        ///   Check that the result of a C call was successful
        ///   <para>
        ///     This usually means that the method is expected to return 0.
        ///     In some rare cases, some methods may return negative values for errors and
        ///     positive values carrying information. Those positive values should be interpreted
        ///     as successful calls as well.
        ///   </para>
        /// </summary>
        /// <param name = "result">The result to examine.</param>
        /// <param name = "allowPositiveResult">False to only allow success when comparing against 0,
        ///   True when positive values are allowed as well.</param>
        public static void Success(int result, bool allowPositiveResult = false)
        {
            if (result == (int)GitErrorCode.GIT_OK)
            {
                return;
            }

            if (allowPositiveResult && result > (int)GitErrorCode.GIT_OK)
            {
                return;
            }

            GitError error = NativeMethods.giterr_last().MarshalAsGitError();

            var errorMessage = (string)marshaler.MarshalNativeToManaged(error.Message);

            throw new LibGit2Exception(
                      String.Format(CultureInfo.InvariantCulture, "An error was raised by libgit2. Class = {0} ({1}).{2}{3}",
                                    Enum.GetName(typeof(GitErrorType), error.Klass),
                                    result,
                                    Environment.NewLine,
                                    errorMessage));
        }
示例#2
0
        private static IList <string> BuildListOf(UnSafeNativeMethods.git_strarray strArray)
        {
            var list = new List <string>();

            try
            {
                UnSafeNativeMethods.git_strarray *gitStrArray = &strArray;

                uint numberOfEntries = gitStrArray->size;
                for (uint i = 0; i < numberOfEntries; i++)
                {
                    var name = (string)marshaler.MarshalNativeToManaged((IntPtr)gitStrArray->strings[i]);
                    list.Add(name);
                }

                list.Sort(StringComparer.Ordinal);
            }
            finally
            {
                UnSafeNativeMethods.git_strarray_free(ref strArray);
            }

            return(list);
        }