private static unsafe void Marshal(Value value, AnsiString *objT, Tracker state) { if (value is null) { return; } Marshal(value.GetText(), objT, state); }
// private static unsafe void Marshal<T>(string text, T* objT, Tracker state) where T : unmanaged, Enum // { // if (Enum.TryParse(text, false, out T value)) // { // T result = (T)Enum.Parse(typeof(T), text, false); // state.InplaceEndianToPlatform((uint*)&result); // *objT = result; // } // } // // private static unsafe void Marshal<T>(Value value, T* objT, Tracker state) where T : unmanaged, Enum // { // if (value is null) // { // return; // } // Marshal(value.GetText(), objT, state); // } public static unsafe void Marshal(string text, AnsiString *objT, Tracker state) { uint length = (uint)text.Length; uint textLength = length; state.InplaceEndianToPlatform(&textLength); objT->Length = (int)textLength; using (Tracker.Context context = state.Push((void **)&objT->Target, 1u, length + 1)) { sbyte *str = objT->Target; IntPtr hText = SMarshal.StringToHGlobalAnsi(text); sbyte *pText = (sbyte *)hText; int c; do { *str = *pText; ++pText; c = *str; ++str; }while (c != 0); SMarshal.FreeHGlobal(hText); } }