本文整理汇总了C#中Slice.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# Slice.ToArray方法的具体用法?C# Slice.ToArray怎么用?C# Slice.ToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slice
的用法示例。
在下文中一共展示了Slice.ToArray方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestEmptySliceAtMid
public void TestEmptySliceAtMid()
{
Slice<int> x = new Slice<int>(new[] { 1, 2, 3, 4 });
x = x.Slc(1, 1);
Assert.IsEmpty(x.ToArray());
}
示例2: TestSlice
public void TestSlice()
{
var slice = new Slice<int>(new []{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, 3, 5);
Assert.AreEqual(5, slice.Count);
Assert.AreEqual(6, slice[3]);
Assert.IsTrue(slice.SequenceEqual(new []{3, 4, 5, 6, 7}));
Assert.IsTrue(slice.ToArray().SequenceEqual(new []{3, 4, 5, 6, 7}));
}
示例3: ProcessSymmetricCrypt
private static void ProcessSymmetricCrypt(Slice<byte> cryptProcessingBuffer, Slice<byte> target, Slice<byte> blocks, byte length, bool encrypt)
{
if ((length % 8) != 0)
throw new ArgumentOutOfRangeException(nameof(length), "Length must be a multiple of 8");
var temp = new byte[8];
var blockCount = length / 8;
for (var index = 0; index != blockCount; ++index)
{
CopyReverse4X2(temp.ToSlice(), blocks.ToSlice(index * 8, 0x08));
uint itemLo, itemHi;
var isDecryption = !encrypt;
if (isDecryption)
{
itemLo = BitConverter.ToUInt32(temp, 0);
itemHi = BitConverter.ToUInt32(temp, 4);
}
else
{
itemLo = BitConverter.ToUInt32(temp, 0);
var tempLo = BitConverter.ToUInt32(cryptProcessingBuffer.ToArray(0x80, 4), 0);
itemLo ^= tempLo;
itemHi = BitConverter.ToUInt32(temp, 4);
var tempHi = BitConverter.ToUInt32(cryptProcessingBuffer.ToArray(0x84, 4), 0);
itemHi ^= tempHi;
}
PerformCrypt(cryptProcessingBuffer.ToArray(), ref itemLo, ref itemHi);
if (isDecryption)
{
var tempLo = BitConverter.ToUInt32(cryptProcessingBuffer.ToArray(0x80, 4), 0);
var tempHi = BitConverter.ToUInt32(cryptProcessingBuffer.ToArray(0x84, 4), 0);
itemLo ^= tempLo;
itemHi ^= tempHi;
cryptProcessingBuffer.ToSlice(0x80, 8).CopyFrom(temp);
}
else
{
cryptProcessingBuffer.ToSlice(0x80, 4).CopyFrom(BitConverter.GetBytes(itemLo));
cryptProcessingBuffer.ToSlice(0x84, 4).CopyFrom(BitConverter.GetBytes(itemHi));
}
WriteToBigEndian32(target.ToSlice(index * 8, 8), itemLo, itemHi);
}
}