本文整理汇总了C#中Mapper.TryGet方法的典型用法代码示例。如果您正苦于以下问题:C# Mapper.TryGet方法的具体用法?C# Mapper.TryGet怎么用?C# Mapper.TryGet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mapper
的用法示例。
在下文中一共展示了Mapper.TryGet方法的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: Insert
public void Insert()
{
var mapper = new Mapper<int>();
const int Input_A = 21;
const int Input_B = 42;
int result;
Assert.IsTrue(mapper.Insert(0, Input_A));
Assert.IsTrue(mapper.TryGet(0, out result));
Assert.AreEqual(Input_A, result);
Assert.IsFalse(mapper.Insert(0, Input_B));
Assert.IsTrue(mapper.TryGet(0, out result));
Assert.AreEqual(Input_A, result);
Assert.IsFalse(mapper.Insert(0, Input_A, out result));
Assert.AreEqual(Input_A, result);
Assert.IsTrue(mapper.TryGet(0, out result));
Assert.AreEqual(Input_A, result);
Assert.AreEqual(1, mapper.Count);
}
示例4: GetNotExisting
public void GetNotExisting()
{
var mapper = new Mapper<int>();
int result;
Assert.IsFalse(mapper.TryGet(0, out result));
Assert.AreEqual(default(int), result);
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);
}