Skip to content

Commit f340a32

Browse files
committed
fixup! Make string marshaling either lax or strict
1 parent b1e8f5f commit f340a32

File tree

2 files changed

+7
-24
lines changed

2 files changed

+7
-24
lines changed

LibGit2Sharp/Core/FilePathMarshaler.cs

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,6 @@ public override IntPtr MarshalManagedToNative(Object managedObj)
7575
return FromManaged(filePath);
7676
}
7777

78-
public override Object MarshalNativeToManaged(IntPtr pNativeData)
79-
{
80-
throw new InvalidOperationException(
81-
string.Format("{0} cannot be used to retrieve data from libgit2.", GetType().Name));
82-
}
83-
8478
#endregion
8579

8680
public static IntPtr FromManaged(FilePath filePath)
@@ -99,43 +93,32 @@ public static IntPtr FromManaged(FilePath filePath)
9993
/// converting it to a managed FilePath instance. The marshaler will free the native pointer
10094
/// after conversion.
10195
/// </summary>
102-
internal class LaxFilePathMarshaler : EncodingMarshaler
96+
internal class LaxFilePathMarshaler : LaxUtf8Marshaler
10397
{
10498
private static readonly LaxFilePathMarshaler staticInstance = new LaxFilePathMarshaler();
10599

106-
private static readonly Encoding encoding = new UTF8Encoding(true, false);
107-
108-
public LaxFilePathMarshaler() : base(encoding)
109-
{ }
110-
111100
#region ICustomMarshaler
112101

113-
public override IntPtr MarshalManagedToNative(object managedObj)
114-
{
115-
throw new InvalidOperationException(
116-
string.Format("{0} cannot be used to pass data to libgit2.", GetType().Name));
117-
}
118-
119102
public override Object MarshalNativeToManaged(IntPtr pNativeData)
120103
{
121104
return FromNative(pNativeData);
122105
}
123106

124107
#endregion
125108

126-
public static ICustomMarshaler GetInstance(String cookie)
109+
public new static ICustomMarshaler GetInstance(String cookie)
127110
{
128111
return staticInstance;
129112
}
130113

131-
public static FilePath FromNative(IntPtr pNativeData)
114+
public new static FilePath FromNative(IntPtr pNativeData)
132115
{
133-
return FromNative(encoding, pNativeData);
116+
return LaxUtf8Marshaler.FromNative(pNativeData);
134117
}
135118

136-
public static FilePath FromBuffer(byte[] buffer)
119+
public new static FilePath FromBuffer(byte[] buffer)
137120
{
138-
return FromBuffer(encoding, buffer);
121+
return LaxUtf8Marshaler.FromBuffer(buffer);
139122
}
140123
}
141124
}

LibGit2Sharp/Core/Utf8Marshaler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public static string FromNative(IntPtr pNativeData)
115115
return FromNative(encoding, pNativeData);
116116
}
117117

118-
public static String FromNative(IntPtr pNativeData, int length)
118+
public static string FromNative(IntPtr pNativeData, int length)
119119
{
120120
return FromNative(encoding, pNativeData, length);
121121
}

0 commit comments

Comments
 (0)