本文整理汇总了C#中CircularBuffer.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# CircularBuffer.ToArray方法的具体用法?C# CircularBuffer.ToArray怎么用?C# CircularBuffer.ToArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CircularBuffer
的用法示例。
在下文中一共展示了CircularBuffer.ToArray方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CircularBuffer_Enqueue
public void CircularBuffer_Enqueue()
{
var buffer = new CircularBuffer<string>(10);
buffer.Enqueue("test");
buffer.Enqueue("string");
CollectionAssert.AreEqual(new[] { "test", "string" }, buffer.ToArray());
Assert.AreEqual(2, buffer.Count);
Assert.AreEqual(10, buffer.Capacity);
Assert.AreEqual(0, buffer.Head);
Assert.AreEqual(2, buffer.Tail);
Assert.IsTrue(buffer.Contains("string"));
Assert.IsFalse(buffer.Contains("other string"));
}
示例2: CircularBuffer_Dequeue
public void CircularBuffer_Dequeue()
{
int[] data = { 0, 1, 2, 3 };
var buffer = new CircularBuffer<int>(data.Length);
buffer.EnqueueRange(data, 0, data.Length);
buffer.Dequeue();
Assert.AreEqual(3, buffer.Count);
Assert.AreEqual(data.Length, buffer.Capacity);
Assert.AreEqual(1, buffer.Head);
Assert.AreEqual(0, buffer.Tail);
Assert.IsTrue(buffer.Contains(1));
Assert.IsFalse(buffer.Contains(0));
CollectionAssert.AreEqual(new[] { 1, 2, 3 }, buffer.ToArray());
}
示例3: CircularBuffer_EnqueueOverwriteAllowed
public void CircularBuffer_EnqueueOverwriteAllowed()
{
string[] data = { "a", "b", "c", "d" };
var buffer = new CircularBuffer<string>(data.Length);
buffer.EnqueueRange(data, 0, data.Length);
buffer.Enqueue("z");
CollectionAssert.AreEqual(new[] { "z", "b", "c", "d" }, buffer.ToArray());
Assert.AreEqual(data.Length, buffer.Count);
Assert.AreEqual(data.Length, buffer.Capacity);
Assert.AreEqual(0, buffer.Head);
Assert.AreEqual(1, buffer.Tail);
Assert.IsTrue(buffer.Contains("z"));
Assert.IsFalse(buffer.Contains("a"));
}
示例4: CircularBuffer_EnqueueAfterTrimExcess
public void CircularBuffer_EnqueueAfterTrimExcess()
{
var buffer = new CircularBuffer<string>(10);
buffer.EnqueueRange(new[] { "a", "b", "c" }, 0, 3);
buffer.TrimExcess();
buffer.Enqueue("z");
CollectionAssert.AreEqual(new[] { "z", "b", "c" }, buffer.ToArray());
Assert.AreEqual(3, buffer.Count);
Assert.AreEqual(3, buffer.Capacity);
Assert.AreEqual(0, buffer.Head);
Assert.AreEqual(1, buffer.Tail);
Assert.IsTrue(buffer.Contains("z"));
Assert.IsFalse(buffer.Contains("a"));
}
示例5: Deserialize
protected override Packet Deserialize(CircularBuffer<byte> buffer)
{
var parsed = parser.Execute(new ArraySegment<byte>(buffer.ToArray()));
buffer.Skip(parsed);
if (processed.Count > 0)
{
var data = processed.Dequeue();
var id = Int32.Parse(data["packetId"]);
var type = Packet.GetTypeById(id);
if (type == null)
return null;
var packet = Activator.CreateInstance(type);
if (packet == null)
Console.WriteLine("packet is null");
foreach(var field in data)
{
var dest = type.GetField(field.Key);
var value = Convert.ChangeType(field.Value, dest.FieldType);
dest.SetValue(packet, value);
}
Console.WriteLine(packet.GetType());
return (Packet)packet;
}
else
return null;
}
示例6: Add_ToArray_ProperlyWorks
public void Add_ToArray_ProperlyWorks()
{
var buffer = new CircularBuffer<int>(3);
buffer.Add(1);
buffer.Add(2);
buffer.Add(3);
buffer.Add(4);
buffer.Add(5);
buffer.Add(6);
buffer.Add(7);
buffer.Add(8);
var result = buffer.ToArray();
Assert.AreEqual(3, result.Length);
Assert.AreEqual(6, result.Skip(0).First());
Assert.AreEqual(7, result.Skip(1).First());
Assert.AreEqual(8, result.Skip(2).First());
}