Skip to content

Commit 5704973

Browse files
committed
Add FilePathMarshaler.FromManaged() and FromNative()
1 parent 78eb071 commit 5704973

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

LibGit2Sharp/Core/FilePathMarshaler.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ public override object MarshalNativeToManaged(IntPtr pNativeData)
2727
return (FilePath)NativeToString(pNativeData);
2828
}
2929

30+
public static IntPtr FromManaged(FilePath managedObj)
31+
{
32+
return staticInstance.MarshalManagedToNative(managedObj);
33+
}
34+
35+
public new static FilePath FromNative(IntPtr pNativeData)
36+
{
37+
return (FilePath)staticInstance.MarshalNativeToManaged(pNativeData);
38+
}
39+
3040
public new static ICustomMarshaler GetInstance(string cookie)
3141
{
3242
return staticInstance;

LibGit2Sharp/Core/GitDiff.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,13 @@ internal class GitStrArrayIn : IDisposable
2626

2727
public static GitStrArrayIn BuildFrom(FilePath[] paths)
2828
{
29-
var marshaler = FilePathMarshaler.GetInstance(string.Empty);
30-
3129
var nbOfPaths = paths.Length;
3230
var pathPtrs = new IntPtr[nbOfPaths];
3331

3432
for (int i = 0; i < nbOfPaths; i++)
3533
{
3634
var s = paths[i];
37-
pathPtrs[i] = marshaler.MarshalManagedToNative(s);
35+
pathPtrs[i] = FilePathMarshaler.FromManaged(s);
3836
}
3937

4038
int dim = IntPtr.Size * nbOfPaths;

LibGit2Sharp/IndexEntry.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ public class IndexEntry : IEquatable<IndexEntry>
1414

1515
private Func<FileStatus> state;
1616

17-
private static readonly Utf8Marshaler marshaler = (Utf8Marshaler)Utf8Marshaler.GetInstance(string.Empty);
18-
1917
/// <summary>
2018
/// State of the version of the <see cref = "Blob" /> pointed at by this <see cref = "IndexEntry" />,
2119
/// compared against the <see cref = "Blob" /> known from the <see cref = "Repository.Head" /> and the file in the working directory.
@@ -39,7 +37,7 @@ internal static IndexEntry CreateFromPtr(Repository repo, IndexEntrySafeHandle h
3937
{
4038
GitIndexEntry entry = handle.MarshalAsGitIndexEntry();
4139

42-
FilePath path = (string)marshaler.MarshalNativeToManaged(entry.Path);
40+
var path = FilePathMarshaler.FromNative(entry.Path);
4341

4442
return new IndexEntry
4543
{

0 commit comments

Comments
 (0)