本文整理汇总了C#中Parameters.Unlock方法的典型用法代码示例。如果您正苦于以下问题:C# Parameters.Unlock方法的具体用法?C# Parameters.Unlock怎么用?C# Parameters.Unlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parameters
的用法示例。
在下文中一共展示了Parameters.Unlock方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: testForLocking
public void testForLocking()
{
parameters.SetInteger("name", 123);
bool IsLocked = parameters.IsLocked("name");
Assert.IsFalse(IsLocked);
long key = 1234567890;
parameters.Lock("name", key);
IsLocked = parameters.IsLocked("name");
Assert.IsTrue(IsLocked);
try
{
parameters.Lock("name", key);
Assert.Fail("should never reach here");
}
catch(BadStateException e)
{
// already locked
Assert.AreEqual(
"The object 'name' is not in the appropriate state.",
e.Message);
}
try
{
// cannot modify
parameters.SetInteger("name", 456);
Assert.Fail("should never reach here");
}
catch(BadStateException e)
{
// locked, cannot modify
Assert.AreEqual(
"The object 'name' is not in the appropriate state.",
e.Message);
}
try
{
parameters.Unlock("name", key + 1);
Assert.Fail("should never reach here");
}
catch(UnexpectedValueException e)
{
// bad key
Assert.AreEqual("Unexpected value: bad key", e.Message);
}
parameters.Unlock("name", key);
IsLocked = parameters.IsLocked("name");
Assert.IsFalse(IsLocked);
try
{
parameters.Unlock("name", key);
Assert.Fail("should never reach here");
}
catch(BadStateException e)
{
// already unlocked
Assert.AreEqual(
"The object 'name' is not in the appropriate state.",
e.Message);
}
// unlocked, can modify
parameters.SetInteger("name", 456);
int value = parameters.GetInteger("name");
Assert.IsTrue(value == 456);
// nested test
Parameters nested = new Parameters();
parameters.SetNestedParameters("nested", nested);
nested.SetInteger("internal", 789);
Parameters nested2 = new Parameters();
nested.SetNestedParameters("more nested", nested2);
nested2.SetInteger("more internal", 987);
// lock something within the hierarchy
long otherKey = 987654321;
nested.Lock("internal", otherKey);
try
{
// cannot modify
nested.SetInteger("internal", 123);
Assert.Fail("should never reach here");
}
//.........这里部分代码省略.........