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; } }