本文整理汇总了C#中AtomicComposition.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# AtomicComposition.SetValue方法的具体用法?C# AtomicComposition.SetValue怎么用?C# AtomicComposition.SetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AtomicComposition
的用法示例。
在下文中一共展示了AtomicComposition.SetValue方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: ChangeExports
private void ChangeExports(List<Export> newExports)
{
using (var atomicComposition = new AtomicComposition())
{
atomicComposition.AddCompleteAction(() => this._exports = newExports);
atomicComposition.SetValue(this, newExports);
var addedExports = newExports.Except(this._exports).Select(export => export.Definition);
var removedExports = this._exports.Except(newExports).Select(export => export.Definition);
this.OnExportsChanging(new ExportsChangeEventArgs(addedExports, removedExports, atomicComposition));
atomicComposition.AddCompleteAction(() => this.OnExportsChanged(
new ExportsChangeEventArgs(addedExports, removedExports, null)));
atomicComposition.Complete();
}
}
示例5: 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);
}
示例6: 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);
}
示例7: 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);
}
示例8: AtomicComposition_CompleteValues
public void AtomicComposition_CompleteValues()
{
object key1 = new Object();
object key2 = new Object();
using (var contextA = new AtomicComposition())
{
TestNoValue(contextA, key1);
TestNoValue(contextA, key2);
contextA.SetValue(key1, "Hello");
TestValue(contextA, key1, "Hello");
TestNoValue(contextA, key2);
// Try overwriting
using (var contextB = new AtomicComposition(contextA))
{
TestValue(contextB, key1, "Hello");
TestNoValue(contextB, key2);
contextB.SetValue(key1, "Greetings");
TestValue(contextB, key1, "Greetings");
TestNoValue(contextB, key2);
contextB.Complete();
}
TestValue(contextA, key1, "Greetings");
TestNoValue(contextA, key2);
// Try overwrite with revert
using (var contextC = new AtomicComposition(contextA))
{
TestValue(contextC, key1, "Greetings");
TestNoValue(contextC, key2);
contextC.SetValue(key1, "Goodbye");
contextC.SetValue(key2, "Goodbye, Again");
TestValue(contextC, key1, "Goodbye");
TestValue(contextC, key2, "Goodbye, Again");
// Don't complete
}
TestValue(contextA, key1, "Greetings");
TestNoValue(contextA, key2);
contextA.Complete();
}
}
示例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: 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);
}
示例11: 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);
}
示例12: 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);
}
}
示例13: 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;
}