本文整理汇总了C#中System.Runtime.InteropServices.StringBuffer.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# StringBuffer.ToString方法的具体用法?C# StringBuffer.ToString怎么用?C# StringBuffer.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Runtime.InteropServices.StringBuffer
的用法示例。
在下文中一共展示了StringBuffer.ToString方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReduceLength
public void ReduceLength()
{
using (var buffer = new StringBuffer("Food"))
{
Assert.Equal((ulong)5, buffer.CharCapacity);
buffer.Length = 3;
Assert.Equal("Foo", buffer.ToString());
// Shouldn't reduce capacity when dropping length
Assert.Equal((ulong)5, buffer.CharCapacity);
}
}
示例2: Main
static void Main(string[] args)
{
var f = new StringBuffer();
f.AppendFormat(formatTest, v1, v2);
Console.WriteLine(f.ToString());
Console.WriteLine(formatTest, v1, v2);
// test custom formatters
StringBuffer.SetCustomFormatter<Blah>(CustomFormat);
f.Clear();
f.AppendFormat("Hello {0:yes}{0:no}", new Blah { Thing = 42 });
Console.WriteLine(f.ToString());
// test static convenience method
Console.WriteLine(StringBuffer.Format(formatTest, v1, v2));
PerfTest();
#if DEBUG
Console.ReadLine();
#endif
}
示例3: CreateFromString
public unsafe void CreateFromString()
{
string testString = "Test";
using (var buffer = new StringBuffer(testString))
{
Assert.Equal((ulong)testString.Length, buffer.Length);
Assert.Equal((ulong)testString.Length + 1, buffer.CharCapacity);
for (int i = 0; i < testString.Length; i++)
{
Assert.Equal(testString[i], buffer[(ulong)i]);
}
// Check the null termination
Assert.Equal('\0', buffer.CharPointer[testString.Length]);
Assert.Equal(testString, buffer.ToString());
}
}
示例4: NewGetCurrentDirectory
private static string NewGetCurrentDirectory()
{
using (StringBuffer buffer = new StringBuffer(PathInternal.MaxShortPath))
{
uint result = 0;
while ((result = Win32Native.GetCurrentDirectoryW(buffer.CharCapacity, buffer.GetHandle())) > buffer.CharCapacity)
{
// Reported size is greater than the buffer size. Increase the capacity.
// The size returned includes the null only if more space is needed (this case).
buffer.EnsureCharCapacity(result);
}
if (result == 0)
__Error.WinIOError();
buffer.Length = result;
#if !PLATFORM_UNIX
if (buffer.Contains('~'))
return LongPathHelper.GetLongPathName(buffer);
#endif
return buffer.ToString();
}
}
示例5: GetLongPathName
unsafe internal static string GetLongPathName(string path)
{
using (StringBuffer outputBuffer = new StringBuffer((uint)path.Length))
{
uint result = 0;
while ((result = Win32Native.GetLongPathNameW(path, outputBuffer.GetHandle(), outputBuffer.CharCapacity)) > outputBuffer.CharCapacity)
{
// Reported size (which does not include the null) is greater than the buffer size. Increase the capacity.
outputBuffer.EnsureCharCapacity(result);
}
if (result == 0)
{
// Failure, get the error and throw
GetErrorAndThrow(path);
}
outputBuffer.Length = result;
return outputBuffer.ToString();
}
}
示例6: CopyToBufferString
public void CopyToBufferString(string destination, string content, ulong destinationIndex, ulong bufferIndex, ulong count, string expected)
{
using (var buffer = new StringBuffer(content))
using (var destinationBuffer = new StringBuffer(destination))
{
buffer.CopyTo(bufferIndex, destinationBuffer, destinationIndex, count);
Assert.Equal(expected, destinationBuffer.ToString());
}
}
示例7: CopyFromString
public void CopyFromString(string content, string source, ulong bufferIndex, int sourceIndex, int count, string expected)
{
using (var buffer = new StringBuffer(content))
{
buffer.CopyFrom(bufferIndex, source, sourceIndex, count);
Assert.Equal(expected, buffer.ToString());
}
}
示例8: TrimEnd
public void TrimEnd(string content, char[] trimChars, string expected)
{
// We want equivalence with built-in string behavior
using (var buffer = new StringBuffer(content))
{
buffer.TrimEnd(trimChars);
Assert.Equal(expected, buffer.ToString());
}
}
示例9: AppendTests
public void AppendTests(string source, string value, int startIndex, int count, string expected)
{
// From string
using (var buffer = new StringBuffer(source))
{
buffer.Append(value, startIndex, count);
Assert.Equal(expected, buffer.ToString());
}
// From buffer
using (var buffer = new StringBuffer(source))
using (var valueBuffer = new StringBuffer(value))
{
if (count == -1)
buffer.Append(valueBuffer, (ulong)startIndex, valueBuffer.Length - (ulong)startIndex);
else
buffer.Append(valueBuffer, (ulong)startIndex, (ulong)count);
Assert.Equal(expected, buffer.ToString());
}
}
示例10: GetCurrentDirectory
/*===============================CurrentDirectory===============================
**Action: Provides a getter and setter for the current directory. The original
** current DirectoryInfo is the one from which the process was started.
**Returns: The current DirectoryInfo (from the getter). Void from the setter.
**Arguments: The current DirectoryInfo to which to switch to the setter.
**Exceptions:
==============================================================================*/
public static String GetCurrentDirectory()
{
// Start with a buffer the size of MAX_PATH
using (StringBuffer buffer = new StringBuffer(260))
{
uint result = 0;
while ((result = Win32Native.GetCurrentDirectoryW(buffer.CharCapacity, buffer.GetHandle())) > buffer.CharCapacity)
{
// Reported size is greater than the buffer size. Increase the capacity.
// The size returned includes the null only if more space is needed (this case).
buffer.EnsureCharCapacity(result);
}
if (result == 0)
__Error.WinIOError();
buffer.Length = result;
#if !PLATFORM_UNIX
if (buffer.Contains('~'))
return Path.GetFullPath(buffer.ToString());
#endif
return buffer.ToString();
}
}