当前位置: 首页>>代码示例>>C#>>正文


C# String.SetTrailByte方法代码示例

本文整理汇总了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;
            } 
        }
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:30,代码来源:StubHelpers.cs


注:本文中的String.SetTrailByte方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。