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