Welcome to mirror list, hosted at ThFree Co, Russian Federation.

IntPtrExtensions.cs « Core « LibGit2Sharp - github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 314a16834e325969399401ea214b41d5bd8dc136 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
using System;
using System.Runtime.InteropServices;

namespace LibGit2Sharp.Core
{
    internal static class IntPtrExtensions
    {
        public static T MarshalAs<T>(this IntPtr ptr, bool throwWhenNull = true)
        {
            if (!throwWhenNull && ptr == IntPtr.Zero)
            {
                return default(T);
            }
            return (T)Marshal.PtrToStructure(ptr, typeof(T));
        }
    }
}