You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
512 B
20 lines
512 B
using System.Runtime.InteropServices; |
|
using static flecs_hub.flecs; |
|
|
|
namespace gaemstone; |
|
|
|
internal static class CStringExtensions |
|
{ |
|
public static string ToStringAndFree(this Runtime.CString str) |
|
{ |
|
var result = Marshal.PtrToStringAnsi(str)!; |
|
Marshal.FreeHGlobal(str); |
|
return result; |
|
} |
|
|
|
public static void Set(this ref Runtime.CString str, string? value) |
|
{ |
|
if (!str.IsNull) Marshal.FreeHGlobal(str); |
|
str = (value != null) ? new(Marshal.StringToHGlobalAnsi(value)) : default; |
|
} |
|
}
|
|
|