本文整理汇总了C#中Mapper.Exchange方法的典型用法代码示例。如果您正苦于以下问题:C# Mapper.Exchange方法的具体用法?C# Mapper.Exchange怎么用?C# Mapper.Exchange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mapper
的用法示例。
在下文中一共展示了Mapper.Exchange方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}