本文整理汇总了C#中AtomicComposition.TryGetValue方法的典型用法代码示例。如果您正苦于以下问题:C# AtomicComposition.TryGetValue方法的具体用法?C# AtomicComposition.TryGetValue怎么用?C# AtomicComposition.TryGetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AtomicComposition
的用法示例。
在下文中一共展示了AtomicComposition.TryGetValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetValue_ToNull_ShouldBeAllowed
public void SetValue_ToNull_ShouldBeAllowed()
{
var ct = new AtomicComposition();
ct.SetValue(ct, null);
object value = new object();
Assert.IsTrue(ct.TryGetValue(ct, out value));
Assert.IsNull(value);
}
示例2: AfterComplete_AllMethodsShouldThrow
public void AfterComplete_AllMethodsShouldThrow()
{
var ct = new AtomicComposition();
ct.Complete();
ExceptionAssert.Throws<InvalidOperationException>(() => ct.AddCompleteAction(() => ct = null));
ExceptionAssert.Throws<InvalidOperationException>(() => ct.Complete());
ExceptionAssert.Throws<InvalidOperationException>(() => ct.SetValue(ct, 10));
object value;
ExceptionAssert.Throws<InvalidOperationException>(() => ct.TryGetValue(ct, out value));
}
示例3: Dispose_AllMethodsShouldThrow
public void Dispose_AllMethodsShouldThrow()
{
var ct = new AtomicComposition();
ct.Dispose();
ExceptionAssert.ThrowsDisposed(ct, () => ct.AddCompleteAction(() => ct = null));
ExceptionAssert.ThrowsDisposed(ct, () => ct.Complete());
ExceptionAssert.ThrowsDisposed(ct, () => ct.SetValue(ct, 10));
object value;
ExceptionAssert.ThrowsDisposed(ct, () => ct.TryGetValue(ct, out value));
}
示例4: SetValue_Reference_ShouldBeAllowed
public void SetValue_Reference_ShouldBeAllowed()
{
var ct = new AtomicComposition();
var sb = new StringBuilder();
ct.SetValue(ct, sb);
StringBuilder value;
Assert.IsTrue(ct.TryGetValue(ct, out value));
Assert.AreEqual(sb, value);
}
示例5: SetValue_ValueType_ShouldBeAllowed
public void SetValue_ValueType_ShouldBeAllowed()
{
var ct = new AtomicComposition();
ct.SetValue(ct, 45);
int value;
Assert.IsTrue(ct.TryGetValue(ct, out value));
Assert.AreEqual(45, value);
}
示例6: SetQuery
private void SetQuery(AtomicComposition context, object key, Func<int, Func<int, bool>, bool> query)
{
Func<int, bool> parentQuery;
context.TryGetValue(key, out parentQuery);
Func<int, bool> queryFunction = parameter => { return query(parameter, parentQuery); };
context.SetValue(key, queryFunction);
}
示例7: TestValue
private void TestValue(AtomicComposition context, object key, string expectedValue)
{
string value;
Assert.IsTrue(context.TryGetValue(key, out value));
Assert.AreEqual(expectedValue, value);
}
示例8: TestQuery
private void TestQuery(AtomicComposition context, object key, int parameter, bool expectation)
{
Func<int, bool> query;
if (context.TryGetValue(key, out query))
Assert.AreEqual(expectation, query(parameter));
}
示例9: NoComplete_ShouldNotCopyValuesToInner
public void NoComplete_ShouldNotCopyValuesToInner()
{
var innerAtomicComposition = new AtomicComposition();
object value;
using (var ct = new AtomicComposition(innerAtomicComposition))
{
ct.SetValue(this, 21);
Assert.IsFalse(innerAtomicComposition.TryGetValue(this, out value));
// Do not call complete
}
// reverify after dispose
Assert.IsFalse(innerAtomicComposition.TryGetValue(this, out value));
}
示例10: TestNoValue
private void TestNoValue(AtomicComposition context, object key)
{
string value;
Assert.IsFalse(context.TryGetValue(key, out value));
}
示例11: Complete_ShouldCopyValuesToInner
public void Complete_ShouldCopyValuesToInner()
{
var innerAtomicComposition = new AtomicComposition();
object value;
using (var ct = new AtomicComposition(innerAtomicComposition))
{
ct.SetValue(this, 21);
Assert.IsFalse(innerAtomicComposition.TryGetValue(this, out value));
ct.Complete();
Assert.IsTrue(innerAtomicComposition.TryGetValue(this, out value));
Assert.AreEqual(21, value);
}
// reverify after dispose
Assert.IsTrue(innerAtomicComposition.TryGetValue(this, out value));
Assert.AreEqual(21, value);
}
示例12: SetValue_ChangeOuterValuesWhileHaveInner_ShouldThrow
public void SetValue_ChangeOuterValuesWhileHaveInner_ShouldThrow()
{
var ct = new AtomicComposition();
var ct2 = new AtomicComposition(ct);
var key = new object();
ExceptionAssert.Throws<InvalidOperationException>(() => ct.SetValue(key, 1));
object value;
Assert.IsFalse(ct2.TryGetValue(key, out value));
Assert.IsFalse(ct.TryGetValue(key, out value));
// remove the inner atomicComposition so the outer one becomes unlocked.
ct2.Dispose();
ct.SetValue(key, 2);
Assert.IsTrue(ct.TryGetValue(key, out value));
Assert.AreEqual(2, value);
}
示例13: SetValue_CauseResize_ShouldWorkFine
public void SetValue_CauseResize_ShouldWorkFine()
{
var ct = new AtomicComposition();
var keys = new List<object>();
var values = new List<object>();
for (int i = 0; i < 20; i++)
{
var key = new object();
keys.Add(key);
values.Add(i);
ct.SetValue(key, i);
}
for (int i = 0; i < keys.Count; i++)
{
object value;
Assert.IsTrue(ct.TryGetValue(keys[i], out value));
Assert.AreEqual(i, value);
}
}
示例14: GetExportsCore
protected override IEnumerable<Export> GetExportsCore(ImportDefinition importDefinition, AtomicComposition context)
{
IEnumerable<Export> contextExports;
if (context == null || !context.TryGetValue(this, out contextExports))
{
contextExports = this._exports;
}
List<Export> exports = new List<Export>();
var func = importDefinition.Constraint.Compile();
foreach (Export export in contextExports)
{
if (func(export.Definition))
{
exports.Add(export);
}
}
return exports;
}
示例15: GetEngineContext
private EngineContext GetEngineContext(AtomicComposition atomicComposition)
{
Assumes.NotNull(atomicComposition);
EngineContext engineContext;
if (!atomicComposition.TryGetValue(this, true, out engineContext))
{
EngineContext parentContext;
atomicComposition.TryGetValue(this, false, out parentContext);
engineContext = new EngineContext(this, parentContext);
atomicComposition.SetValue(this, engineContext);
atomicComposition.AddCompleteAction(engineContext.Complete);
}
return engineContext;
}