本文整理汇总了C#中Mapper.Set方法的典型用法代码示例。如果您正苦于以下问题:C# Mapper.Set方法的具体用法?C# Mapper.Set怎么用?C# Mapper.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mapper
的用法示例。
在下文中一共展示了Mapper.Set方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Exchange
public void Exchange()
{
var mapper = new Mapper<int>();
const int Input_A = 21;
const int Input_B = 42;
int result;
bool isNew;
mapper.Set(0, Input_A, out isNew);
Assert.IsTrue(isNew);
Assert.IsTrue(mapper.TryGet(0, out result));
Assert.AreEqual(Input_A, result);
Assert.IsFalse(mapper.Exchange(0, Input_B, out result));
Assert.AreEqual(Input_A, result);
Assert.IsTrue(mapper.TryGet(0, out result));
Assert.AreEqual(Input_B, result);
Assert.IsTrue(mapper.Exchange(1, Input_A, out result));
Assert.AreEqual(default(int), result);
Assert.IsTrue(mapper.TryGet(1, out result));
Assert.AreEqual(Input_A, result);
Assert.AreEqual(2, mapper.Count);
}
示例2: CheckIsNew
public void CheckIsNew()
{
var mapper = new Mapper<int>();
const int Input_A = 21;
const int Input_B = 42;
int result;
bool isNew;
mapper.Set(0, Input_A, out isNew);
Assert.IsTrue(isNew);
Assert.IsTrue(mapper.TryGet(0, out result));
Assert.AreEqual(Input_A, result);
mapper.Set(0, Input_B, out isNew);
Assert.IsFalse(isNew);
Assert.IsTrue(mapper.TryGet(0, out result));
Assert.AreEqual(Input_B, result);
Assert.AreEqual(1, mapper.Count);
}
示例3: CopyTo
public void CopyTo()
{
var mapper = new Mapper<int>();
var data = GetSampleData();
foreach (var pair in data)
{
bool isNew;
mapper.Set(pair[0], pair[1], out isNew);
Assert.IsTrue(isNew);
}
Assert.AreEqual(data.Length, mapper.Count);
var target = new int[data.Length];
Array.Sort(data, (pairA, pairB) => pairA[0].CompareTo(pairB[0]));
mapper.CopyTo(target, 0);
for (int index = 0; index < data.Length; index++)
{
var pair = data[index];
var item = target[index];
Assert.AreEqual(pair[1], item);
}
}
示例4: TwoThreadsRemoveAt
public void TwoThreadsRemoveAt()
{
var mapper = new Mapper<int>();
const int Input = 21;
var info = new CircularBucket<string>(16);
var startEvent = new ManualResetEvent(false);
int[] done = {0};
var threads = new[]
{
new Thread
(
() =>
{
int result;
bool isNew;
mapper.Set(0, Input, out isNew);
info.Add("A: Set - was new: " + isNew);
bool removed = mapper.RemoveAt(0, out result);
info.Add(removed ? "A: Removed" : "A: Could not remove");
Interlocked.Increment(ref done[0]);
}
),
new Thread
(
() =>
{
int result;
bool isNew;
mapper.Set(0, Input, out isNew);
info.Add("B: Set - was new: " + isNew);
bool removed = mapper.RemoveAt(0, out result);
info.Add(removed ? "B: Removed" : "B: Could not remove");
Interlocked.Increment(ref done[0]);
}
)
};
threads[0].Start();
threads[1].Start();
startEvent.Set();
while (true)
{
if (Thread.VolatileRead(ref done[0]) == 2)
{
break;
}
Thread.Sleep(0);
}
Assert.AreEqual(0, mapper.Count);
}
示例5: SparseData
public void SparseData()
{
var mapper = new Mapper<int>();
var data = GetSampleData();
foreach (var pair in data)
{
bool isNew;
mapper.Set(pair[0], pair[1], out isNew);
Assert.IsTrue(isNew);
}
Assert.AreEqual(data.Length, mapper.Count);
foreach (var pair in data)
{
int result;
Assert.IsTrue(mapper.TryGet(pair[0], out result));
Assert.AreEqual(pair[1], result);
}
Array.Sort(data, (pairA, pairB) => pairA[0].CompareTo(pairB[0]));
var index = 0;
foreach (var item in mapper)
{
Assert.AreEqual(data[index][1], item);
index++;
}
Assert.AreEqual(mapper.Count, index);
}
示例6: SetToNull
public void SetToNull()
{
var mapper = new Mapper<string>();
string result;
bool isNew;
Assert.IsTrue(mapper.Insert(0, null));
Assert.IsTrue(mapper.TryGet(0, out result));
Assert.AreEqual(null, result);
Assert.IsTrue(mapper.RemoveAt(0, out result));
Assert.AreEqual(null, result);
Assert.IsTrue(mapper.Exchange(0, null, out result));
Assert.AreEqual(null, result);
Assert.IsFalse(mapper.Insert(0, null, out result));
Assert.AreEqual(null, result);
mapper.Set(0, "Hello", out isNew);
Assert.IsFalse(isNew);
Assert.IsTrue(mapper.TryGet(0, out result));
Assert.AreEqual("Hello", result);
mapper.Set(0, null, out isNew);
Assert.IsFalse(isNew);
Assert.IsTrue(mapper.TryGet(0, out result));
Assert.AreEqual(null, result);
mapper.Exchange(0, "Hello", out result);
Assert.AreEqual(null, result);
mapper.Exchange(0, null, out result);
Assert.AreEqual("Hello", result);
Assert.AreEqual(1, mapper.Count);
}
示例7: SetAndGet
public void SetAndGet()
{
var mapper = new Mapper<int>();
const int Input = 42;
int result;
bool isNew;
mapper.Set(0, Input, out isNew);
Assert.IsTrue(isNew);
Assert.IsTrue(mapper.TryGet(0, out result));
Assert.AreEqual(Input, result);
Assert.AreEqual(1, mapper.Count);
}
示例8: RemoveAt
public void RemoveAt()
{
var mapper = new Mapper<int>();
const int Input = 21;
int result;
bool isNew;
//---
mapper.Set(0, Input, out isNew);
Assert.IsTrue(isNew);
Assert.IsTrue(mapper.TryGet(0, out result));
Assert.AreEqual(Input, result);
Assert.IsTrue(mapper.RemoveAt(0, out result));
Assert.AreEqual(Input, result);
Assert.IsFalse(mapper.TryGet(0, out result));
Assert.IsFalse(mapper.RemoveAt(1, out result));
Assert.IsFalse(mapper.TryGet(1, out result));
//---
mapper.Set(0, Input, out isNew);
Assert.IsTrue(isNew);
Assert.IsTrue(mapper.TryGet(0, out result));
Assert.AreEqual(Input, result);
Assert.IsTrue(mapper.RemoveAt(0));
Assert.IsFalse(mapper.TryGet(0, out result));
Assert.IsFalse(mapper.RemoveAt(1));
Assert.IsFalse(mapper.TryGet(1, out result));
Assert.AreEqual(0, mapper.Count);
}