本文整理汇总了C#中String.SetTrailByte方法的典型用法代码示例。如果您正苦于以下问题:C# String.SetTrailByte方法的具体用法?C# String.SetTrailByte怎么用?C# String.SetTrailByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类String
的用法示例。
在下文中一共展示了String.SetTrailByte方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvertToManaged
[System.Security.SecurityCritical] // auto-generated
static internal unsafe string ConvertToManaged(IntPtr bstr)
{
if (IntPtr.Zero == bstr)
{
return null;
}
else
{
uint length = Win32Native.SysStringByteLen(bstr);
// Intentionally checking the number of bytes not characters to match the behavior
// of ML marshalers. This prevents roundtripping of very large strings as the check
// in the managed->native direction is done on String length but considering that
// it's completely moot on 32-bit and not expected to be important on 64-bit either,
// the ability to catch random garbage in the BSTR's length field outweighs this
// restriction. If an ordinary null-terminated string is passed instead of a BSTR,
// chances are that the length field - possibly being unallocated memory - contains
// a heap fill pattern that will have the highest bit set, caught by the check.
StubHelpers.CheckStringLength(length);
string ret = new String((char*)bstr, 0, (int)(length / 2));
if ((length & 1) == 1)
{
// odd-sized strings need to have the trailing byte saved in their [....] block
ret.SetTrailByte(((byte *)bstr.ToPointer())[length - 1]);
}
return ret;
}
}