8000 Merge pull request #1465 from AArnott/fixObsoleteWarnings · libgit2/libgit2sharp@72d20fb · GitHub
[go: up one dir, main page]

Skip to content

Commit 72d20fb

Browse files
authored
Merge pull request #1465 from AArnott/fixObsoleteWarnings
Fix warnings from use of obsolete members
2 parents e323be6 + f066dc7 commit 72d20fb

File tree

8 files changed

+42
-7
lines changed
  • 8 files changed

    +42
    -7
    lines changed

    LibGit2Sharp/Core/ArrayMarshaler.cs

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -13,7 +13,7 @@ public ArrayMarshaler(T[] objs)
    1313

    1414
    for (var i = 0; i < objs.Length; i++)
    1515
    {
    16-
    IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(T)));
    16+
    IntPtr ptr = Marshal.AllocHGlobal(MarshalPortable.SizeOf<T>());
    1717
    ptrs[i] = ptr;
    1818
    Marshal.StructureToPtr(objs[i], ptr, false);
    1919
    }

    LibGit2Sharp/Core/GitOdbBackend.cs

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -8,7 +8,7 @@ internal struct GitOdbBackend
    88
    {
    99
    static GitOdbBackend()
    1010
    {
    11-
    GCHandleOffset = Marshal.OffsetOf(typeof(GitOdbBackend), nameof(GCHandle)).ToInt32();
    11+
    GCHandleOffset = MarshalPortable.OffsetOf<GitOdbBackend>(nameof(GCHandle)).ToInt32();
    1212
    }
    1313

    1414
    public uint Version;

    LibGit2Sharp/Core/GitOdbBackendStream.cs

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -15,7 +15,7 @@ internal class GitOdbBackendStream
    1515
    {
    1616
    static GitOdbBackendStream()
    1717
    {
    18-
    GCHandleOffset = Marshal.OffsetOf(typeof(GitOdbBackendStream), nameof(GCHandle)).ToInt32();
    18+
    GCHandleOffset = MarshalPortable.OffsetOf<GitOdbBackendStream>(nameof(GCHandle)).ToInt32();
    1919
    }
    2020

    2121
    public IntPtr Backend;

    LibGit2Sharp/Core/GitSmartSubtransport.cs

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -8,7 +8,7 @@ internal class GitSmartSubtransport
    88
    {
    99
    static GitSmartSubtransport()
    1010
    {
    11-
    GCHandleOffset = Marshal.OffsetOf(typeof(GitSmartSubtransport), nameof(GCHandle)).ToInt32();
    11+
    GCHandleOffset = MarshalPortable.OffsetOf<GitSmartSubtransport>(nameof(GCHandle)).ToInt32();
    1212
    }
    1313

    1414
    public action_callback Action;

    LibGit2Sharp/Core/GitSmartSubtransportStream.cs

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -8,7 +8,7 @@ internal class GitSmartSubtransportStream
    88
    {
    99
    static GitSmartSubtransportStream()
    1010
    {
    11-
    GCHandleOffset = Marshal.OffsetOf(typeof(GitSmartSubtransportStream), nameof(GCHandle)).ToInt32();
    11+
    GCHandleOffset = MarshalPortable.OffsetOf<GitSmartSubtransportStream>(nameof(GCHandle)).ToInt32();
    1212
    }
    1313

    1414
    public IntPtr SmartTransport;

    LibGit2Sharp/Core/MarshalPortable.cs

    Lines changed: 35 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,35 @@
    1+
    using System;
    2+
    using System.Runtime.InteropServices;
    3+
    4+
    namespace LibGit2Sharp.Core
    5+
    {
    6+
    internal static class MarshalPortable
    7+
    {
    8+
    internal static int SizeOf<T>()
    9+
    {
    10+
    #if NET40
    11+
    return Marshal.SizeOf(typeof(T));
    12+
    #else
    13+
    return Marshal.SizeOf<T>();
    14+
    #endif
    15+
    }
    16+
    17+
    internal static IntPtr OffsetOf<T>(string fieldName)
    18+
    {
    19+
    #if NET40
    20+
    return Marshal.OffsetOf(typeof(T), fieldName);
    21+
    #else
    22+
    return Marshal.OffsetOf<T>(fieldName);
    23+
    #endif
    24+
    }
    25+
    26+
    internal static T PtrToStructure<T>(IntPtr ptr)
    27+
    {
    28+
    #if NET40
    29+
    return (T)Marshal.PtrToStructure(ptr, typeof(T));
    30+
    #else
    31+
    return Marshal.PtrToStructure<T>(ptr);
    32+
    #endif
    33+
    }
    34+
    }
    35+
    }

    LibGit2Sharp/Filter.cs

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -261,7 +261,7 @@ int StreamCreateCallback(out IntPtr git_writestream_out, GitFilter self, IntPtr
    261261
    Marshal.StructureToPtr(state.thisStream, state.thisPtr, false);
    262262

    263263
    state.nextPtr = git_writestream_next;
    264-
    state.nextStream = (GitWriteStream)Marshal.PtrToStructure(state.nextPtr, typeof(GitWriteStream));
    264+
    state.nextStream = MarshalPortable.PtrToStructure<GitWriteStream>(state.nextPtr);
    265265

    266266
    state.filterSource = FilterSource.FromNativePtr(filterSourcePtr);
    267267
    state.output = new WriteStream(state.nextStream, state.nextPtr);

    LibGit2Sharp/ObjectDatabase.cs

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -239,7 +239,7 @@ private unsafe Blob CreateBlob(Stream stream, string hintpath, long? numberOfByt
    239239
    }
    240240

    241241
    IntPtr writestream_ptr = Proxy.git_blob_create_fromstream(repo.Handle, hintpath);
    242-
    GitWriteStream writestream = (GitWriteStream)Marshal.PtrToStructure(writestream_ptr, typeof(GitWriteStream));
    242+
    GitWriteStream writestream = MarshalPortable.PtrToStructure<GitWriteStream>(writestream_ptr);
    243243

    244244
    try
    245245
    {

    0 commit comments

    Comments
     (0)
    0