本文整理汇总了C#中Encoding.GetEncoder方法的典型用法代码示例。如果您正苦于以下问题:C# Encoding.GetEncoder方法的具体用法?C# Encoding.GetEncoder怎么用?C# Encoding.GetEncoder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Encoding
的用法示例。
在下文中一共展示了Encoding.GetEncoder方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ValidateSerializeDeserialize
partial static void ValidateSerializeDeserialize(Encoding e)
{
// Make sure the Encoding roundtrips
Assert.Equal(e, BinaryFormatterHelpers.Clone(e));
// Get an encoder and decoder from the encoding, and clone them
Encoder origEncoder = e.GetEncoder();
Decoder origDecoder = e.GetDecoder();
Encoder clonedEncoder = BinaryFormatterHelpers.Clone(origEncoder);
Decoder clonedDecoder = BinaryFormatterHelpers.Clone(origDecoder);
// Encode and decode some text with each pairing
const string InputText = "abcdefghijklmnopqrstuvwxyz";
char[] inputTextChars = InputText.ToCharArray();
var pairs = new[]
{
Tuple.Create(origEncoder, origDecoder),
Tuple.Create(origEncoder, clonedDecoder),
Tuple.Create(clonedEncoder, origDecoder),
Tuple.Create(clonedEncoder, clonedDecoder),
};
var results = new List<char[]>();
foreach (Tuple<Encoder, Decoder> pair in pairs)
{
byte[] encodedBytes = new byte[pair.Item1.GetByteCount(inputTextChars, 0, inputTextChars.Length, true)];
Assert.Equal(encodedBytes.Length, pair.Item1.GetBytes(inputTextChars, 0, inputTextChars.Length, encodedBytes, 0, true));
char[] decodedChars = new char[pair.Item2.GetCharCount(encodedBytes, 0, encodedBytes.Length)];
Assert.Equal(decodedChars.Length, pair.Item2.GetChars(encodedBytes, 0, encodedBytes.Length, decodedChars, 0));
results.Add(decodedChars);
}
// Validate that all of the pairings produced the same results
foreach (char[] a in results)
{
foreach (char[] b in results)
{
Assert.Equal(a, b);
}
}
}
示例2: EncoderTest
public EncoderTest (string cnvout, Encoding encoding) : base (cnvout)
{
enc = encoding.GetEncoder ();
}