Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix warnings from use of obsolete members #1465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LibGit2Sharp/Core/ArrayMarshaler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public ArrayMarshaler(T[] objs)

for (var i = 0; i < objs.Length; i++)
{
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(T)));
IntPtr ptr = Marshal.AllocHGlobal(MarshalPortable.SizeOf<T>());
ptrs[i] = ptr;
Marshal.StructureToPtr(objs[i], ptr, false);
}
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp/Core/GitOdbBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal struct GitOdbBackend
{
static GitOdbBackend()
{
GCHandleOffset = Marshal.OffsetOf(typeof(GitOdbBackend), nameof(GCHandle)).ToInt32();
GCHandleOffset = MarshalPortable.OffsetOf<GitOdbBackend>(nameof(GCHandle)).ToInt32();
}

public uint Version;
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp/Core/GitOdbBackendStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal class GitOdbBackendStream
{
static GitOdbBackendStream()
{
GCHandleOffset = Marshal.OffsetOf(typeof(GitOdbBackendStream), nameof(GCHandle)).ToInt32();
GCHandleOffset = MarshalPortable.OffsetOf<GitOdbBackendStream>(nameof(GCHandle)).ToInt32();
}

public IntPtr Backend;
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp/Core/GitSmartSubtransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal class GitSmartSubtransport
{
static GitSmartSubtransport()
{
GCHandleOffset = Marshal.OffsetOf(typeof(GitSmartSubtransport), nameof(GCHandle)).ToInt32();
GCHandleOffset = MarshalPortable.OffsetOf<GitSmartSubtransport>(nameof(GCHandle)).ToInt32();
}

public action_callback Action;
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp/Core/GitSmartSubtransportStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal class GitSmartSubtransportStream
{
static GitSmartSubtransportStream()
{
GCHandleOffset = Marshal.OffsetOf(typeof(GitSmartSubtransportStream), nameof(GCHandle)).ToInt32();
GCHandleOffset = MarshalPortable.OffsetOf<GitSmartSubtransportStream>(nameof(GCHandle)).ToInt32();
}

public IntPtr SmartTransport;
Expand Down
35 changes: 35 additions & 0 deletions LibGit2Sharp/Core/MarshalPortable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Runtime.InteropServices;

namespace LibGit2Sharp.Core
{
internal static class MarshalPortable
{
internal static int SizeOf<T>()
{
#if NET40
return Marshal.SizeOf(typeof(T));
#else
return Marshal.SizeOf<T>();
#endif
}

internal static IntPtr OffsetOf<T>(string fieldName)
{
#if NET40
return Marshal.OffsetOf(typeof(T), fieldName);
#else
return Marshal.OffsetOf<T>(fieldName);
#endif
}

internal static T PtrToStructure<T>(IntPtr ptr)
{
#if NET40
return (T)Marshal.PtrToStructure(ptr, typeof(T));
#else
return Marshal.PtrToStructure<T>(ptr);
#endif
}
}
}
2 changes: 1 addition & 1 deletion LibGit2Sharp/Filter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ int StreamCreateCallback(out IntPtr git_writestream_out, GitFilter self, IntPtr
Marshal.StructureToPtr(state.thisStream, state.thisPtr, false);

state.nextPtr = git_writestream_next;
state.nextStream = (GitWriteStream)Marshal.PtrToStructure(state.nextPtr, typeof(GitWriteStream));
state.nextStream = MarshalPortable.PtrToStructure<GitWriteStream>(state.nextPtr);

state.filterSource = FilterSource.FromNativePtr(filterSourcePtr);
state.output = new WriteStream(state.nextStream, state.nextPtr);
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp/ObjectDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ private unsafe Blob CreateBlob(Stream stream, string hintpath, long? numberOfByt
}

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

try
{
Expand Down