checkpoint
This commit is contained in:
38
Alpm/Marshalling/UTF8In.cs
Normal file
38
Alpm/Marshalling/UTF8In.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Foodsoft.Alpm.Marshalling
|
||||
{
|
||||
internal readonly struct UTF8In : ICustomMarshaler
|
||||
{
|
||||
private static readonly UTF8In _instance = default;
|
||||
|
||||
public void CleanUpManagedData(object managedObj) { }
|
||||
|
||||
public void CleanUpNativeData(IntPtr pNativeData)
|
||||
{
|
||||
if (pNativeData == IntPtr.Zero)
|
||||
return;
|
||||
Marshal.FreeCoTaskMem(pNativeData);
|
||||
}
|
||||
|
||||
public int GetNativeDataSize() => -1;
|
||||
|
||||
public IntPtr MarshalManagedToNative(object? managedObj)
|
||||
{
|
||||
return Marshal.StringToCoTaskMemUTF8((string?) managedObj);
|
||||
}
|
||||
|
||||
public object MarshalNativeToManaged(IntPtr pNativeData)
|
||||
{
|
||||
return Marshal.PtrToStringUTF8(pNativeData)!;
|
||||
}
|
||||
|
||||
// ReSharper disable once UnusedMember.Local
|
||||
// ReSharper disable once UnusedParameter.Local
|
||||
private static ICustomMarshaler GetInstance(string cookie)
|
||||
{
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
33
Alpm/Marshalling/UTF8Return.cs
Normal file
33
Alpm/Marshalling/UTF8Return.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Foodsoft.Alpm.Marshalling
|
||||
{
|
||||
internal readonly struct UTF8Return : ICustomMarshaler
|
||||
{
|
||||
private static readonly UTF8Return _instance = default;
|
||||
|
||||
// ReSharper disable once UnusedMember.Local
|
||||
// ReSharper disable once UnusedParameter.Local
|
||||
private static ICustomMarshaler GetInstance(string cookie)
|
||||
{
|
||||
return _instance;
|
||||
}
|
||||
|
||||
public void CleanUpManagedData(object managedObj) { }
|
||||
|
||||
public void CleanUpNativeData(IntPtr pNativeData) { }
|
||||
|
||||
public int GetNativeDataSize() => -1;
|
||||
|
||||
public object MarshalNativeToManaged(IntPtr pNativeData)
|
||||
{
|
||||
return Marshal.PtrToStringUTF8(pNativeData)!;
|
||||
}
|
||||
|
||||
public IntPtr MarshalManagedToNative(object managedObj)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user