本文整理汇总了C#中Encoder.GetBytes方法的典型用法代码示例。如果您正苦于以下问题:C# Encoder.GetBytes方法的具体用法?C# Encoder.GetBytes怎么用?C# Encoder.GetBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Encoder
的用法示例。
在下文中一共展示了Encoder.GetBytes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Encoder_GetBytes_Invalid
public static void Encoder_GetBytes_Invalid(Encoder encoder, bool flush)
{
// Chars is null
Assert.Throws<ArgumentNullException>("chars", () => encoder.GetBytes(null, 0, 0, new byte[4], 0, flush));
// CharIndex is invalid
Assert.Throws<ArgumentOutOfRangeException>("charIndex", () => encoder.GetBytes(new char[4], -1, 0, new byte[4], 0, flush));
Assert.Throws<ArgumentOutOfRangeException>("chars", () => encoder.GetBytes(new char[4], 5, 0, new byte[4], 0, flush));
// CharCount is invalid
Assert.Throws<ArgumentOutOfRangeException>("charCount", () => encoder.GetBytes(new char[4], 0, -1, new byte[4], 0, flush));
Assert.Throws<ArgumentOutOfRangeException>("chars", () => encoder.GetBytes(new char[4], 0, 5, new byte[4], 0, flush));
Assert.Throws<ArgumentOutOfRangeException>("chars", () => encoder.GetBytes(new char[4], 1, 4, new byte[4], 0, flush));
// Bytes is null
Assert.Throws<ArgumentNullException>("bytes", () => encoder.GetBytes(new char[1], 0, 1, null, 0, flush));
// ByteIndex is invalid
Assert.Throws<ArgumentOutOfRangeException>("byteIndex", () => encoder.GetBytes(new char[1], 0, 1, new byte[4], -1, flush));
Assert.Throws<ArgumentOutOfRangeException>("byteIndex", () => encoder.GetBytes(new char[1], 0, 1, new byte[4], 5, flush));
// Bytes does not have enough space
int byteCount = encoder.GetByteCount(new char[] { 'a' }, 0, 1, flush);
Assert.Throws<ArgumentException>("bytes", () => encoder.GetBytes(new char[] { 'a' }, 0, 1, new byte[byteCount - 1], 0, flush));
}
示例2: VerificationHelper
private void VerificationHelper(Encoder encoder, char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex,
bool flush, int expectedRetVal, string errorno)
{
int actualRetVal = encoder.GetBytes(chars, charIndex, charCount, bytes, byteIndex, flush);
Assert.Equal(expectedRetVal, actualRetVal);
}