Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ ConvertStringBuilderToNative()

unsafe IntPtr System.StubHelpers.AsAnyMarshaler.ConvertStringBuilderToNative ( StringBuilder pManagedHome,
int dwFlags )
inlineprivate

Definition at line 158 of file AsAnyMarshaler.cs.

159 {
160 int capacity = pManagedHome.Capacity;
161 int length = pManagedHome.Length;
162 if (length > capacity)
163 {
164 ThrowHelper.ThrowInvalidOperationException();
165 }
166 IntPtr intPtr;
167 if (IsAnsi(dwFlags))
168 {
169 StubHelpers.CheckStringLength(capacity);
170 int num = checked(capacity * Marshal.SystemMaxDBCSCharSize + 4);
171 intPtr = Marshal.AllocCoTaskMem(num);
172 byte* ptr = (byte*)(void*)intPtr;
173 *(ptr + num - 3) = 0;
174 *(ptr + num - 2) = 0;
175 *(ptr + num - 1) = 0;
176 if (IsIn(dwFlags))
177 {
178 int num2 = Marshal.StringToAnsiString(pManagedHome.ToString(), ptr, num, IsBestFit(dwFlags), IsThrowOn(dwFlags));
179 }
180 if (IsOut(dwFlags))
181 {
182 backPropAction = BackPropAction.StringBuilderAnsi;
183 }
184 }
185 else
186 {
187 int num3 = checked(capacity * 2 + 4);
188 intPtr = Marshal.AllocCoTaskMem(num3);
189 byte* ptr2 = (byte*)(void*)intPtr;
190 *(ptr2 + num3 - 1) = 0;
191 *(ptr2 + num3 - 2) = 0;
192 if (IsIn(dwFlags))
193 {
194 pManagedHome.InternalCopy(intPtr, length);
195 int num4 = length * 2;
196 ptr2[num4] = 0;
197 (ptr2 + num4)[1] = 0;
198 }
199 if (IsOut(dwFlags))
200 {
201 backPropAction = BackPropAction.StringBuilderUnicode;
202 }
203 }
204 return intPtr;
205 }
static unsafe int StringToAnsiString(string s, byte *buffer, int bufferLength, bool bestFit=false, bool throwOnUnmappableChar=false)
Definition Marshal.cs:1608
static IntPtr AllocCoTaskMem(int cb)
Definition Marshal.cs:1702
static readonly int SystemMaxDBCSCharSize
Definition Marshal.cs:19
override string ToString()
unsafe void InternalCopy(IntPtr dest, int charLen)
static bool IsAnsi(int dwFlags)
static bool IsThrowOn(int dwFlags)
static bool IsIn(int dwFlags)
static bool IsOut(int dwFlags)
static bool IsBestFit(int dwFlags)

References System.Runtime.InteropServices.Marshal.AllocCoTaskMem(), System.StubHelpers.AsAnyMarshaler.backPropAction, System.Text.StringBuilder.Capacity, System.capacity, System.StubHelpers.StubHelpers.CheckStringLength(), System.Text.StringBuilder.InternalCopy(), System.StubHelpers.AsAnyMarshaler.IsAnsi(), System.StubHelpers.AsAnyMarshaler.IsBestFit(), System.StubHelpers.AsAnyMarshaler.IsIn(), System.StubHelpers.AsAnyMarshaler.IsOut(), System.StubHelpers.AsAnyMarshaler.IsThrowOn(), System.length, System.Text.StringBuilder.Length, System.Runtime.InteropServices.Marshal.StringToAnsiString(), System.Runtime.InteropServices.Marshal.SystemMaxDBCSCharSize, System.ThrowHelper.ThrowInvalidOperationException(), and System.Text.StringBuilder.ToString().

Referenced by System.StubHelpers.AsAnyMarshaler.ConvertToNative().