本文整理汇总了C#中Parameters.SetNestedParameters方法的典型用法代码示例。如果您正苦于以下问题:C# Parameters.SetNestedParameters方法的具体用法?C# Parameters.SetNestedParameters怎么用?C# Parameters.SetNestedParameters使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parameters
的用法示例。
在下文中一共展示了Parameters.SetNestedParameters方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: testForNesting
public void testForNesting()
{
parameters.SetInteger("name", 123);
Assert.IsTrue(parameters.Count == 1);
Parameters nested = new Parameters();
parameters.SetNestedParameters("nested", nested);
Assert.IsTrue(parameters.Count == 2);
nested.SetInteger("internal", 456);
Assert.IsTrue(nested.Count == 1);
nested.SetDouble("internal2", 3.125);
Assert.IsTrue(parameters.Count == 2);
Assert.IsTrue(nested.Count == 2);
Parameters tmp = parameters.GetNestedParameters("nested");
Assert.AreEqual(tmp, nested);
Parameters nested2 = new Parameters();
nested.SetNestedParameters("more nested", nested2);
Assert.IsTrue(parameters.Count == 2);
Assert.IsTrue(nested.Count == 3);
nested2.SetInteger("more internal", 789);
Assert.IsTrue(parameters.Count == 2);
Assert.IsTrue(nested.Count == 3);
Assert.IsTrue(nested2.Count == 1);
Assert.AreEqual(parameters.GetType("name"),
Parameters.EntryType.INTEGER);
Assert.AreEqual(parameters.GetType("nested"),
Parameters.EntryType.NESTED_PARAMETERS);
Assert.AreEqual(nested.GetType("internal"),
Parameters.EntryType.INTEGER);
Assert.AreEqual(nested.GetType("internal2"),
Parameters.EntryType.DOUBLE);
Assert.AreEqual(nested.GetType("more nested"),
Parameters.EntryType.NESTED_PARAMETERS);
Assert.AreEqual(nested2.GetType("more internal"),
Parameters.EntryType.INTEGER);
try
{
nested.GetType("blabla");
Assert.Fail("should never reach this point");
}
catch(NoSuchNameException)
{
// expected, ignore
}
IEnumerator<Parameters.Entry> it = parameters.GetEnumerator();
Assert.IsTrue(it.MoveNext());
Parameters.Entry e = it.Current;
Assert.AreEqual(e.Type, Parameters.EntryType.INTEGER);
Assert.IsTrue(it.MoveNext());
e = it.Current;
Assert.AreEqual(e.Type, Parameters.EntryType.NESTED_PARAMETERS);
Parameters n = e.GetNestedParameters();
Assert.IsTrue(n.Count == 3);
Assert.IsFalse(it.MoveNext());
Assert.AreEqual("entry 0:\n"
+ "name: name\n"
+ "integer: 123\n"
+ "entry 1:\n"
+ "name: nested\n"
+ "nested parameters:\n"
+ " entry 0:\n"
+ " name: internal\n"
+ " integer: 456\n"
+ " entry 1:\n"
+ " name: internal2\n"
+ " double: 3.125\n"
+ " entry 2:\n"
+ " name: more nested\n"
+ " nested parameters:\n"
+ " entry 0:\n"
+ " name: more internal\n"
+ " integer: 789\n",
parameters.ToString());
byte[] expected = {
2, 0, 0, 0, // num of entries
4, 0, 0, 0, // length of "name"
(byte)'n', (byte)'a', (byte)'m', (byte)'e',
2, 0, 0, 0, // type code for integer
123, 0, 0, 0, // value
6, 0, 0, 0, // length of "nested"
(byte)'n', (byte)'e', (byte)'s', (byte)'t',
(byte)'e', (byte)'d', 0, 0,
13, 0, 0, 0, // type code for nested
3, 0, 0, 0, // num of entries in nested
8, 0, 0, 0, // length o "internal"
//.........这里部分代码省略.........
示例2: deserializeFromBytes
//.........这里部分代码省略.........
break;
case Parameters.EntryType.BINARY:
{
byte[] value = consumeBinary(bytes);
parameters.SetBinary(entryName, value);
}
break;
case Parameters.EntryType.BOOLEAN_ARRAY:
{
int arrayLength = consumeInt(bytes);
int bytesNeeded =
(arrayLength + BITS_IN_BYTE - 1)
/ BITS_IN_BYTE;
byte[] packedArray =
consumeBytes(bytes, bytesNeeded);
bool[] array = new bool[arrayLength];
for(int j = 0; j != arrayLength; ++j)
{
int bytePosition = j / BITS_IN_BYTE;
int bitPosition = j % BITS_IN_BYTE;
int mask = 1 << bitPosition;
if((packedArray[bytePosition] & mask) != 0)
{
array[j] = true;
}
}
parameters.SetBooleanArray(entryName, array);
}
break;
case Parameters.EntryType.INTEGER_ARRAY:
{
int arrayLength = consumeInt(bytes);
int[] array = new int[arrayLength];
for(int j = 0; j != arrayLength; ++j)
{
array[j] = consumeInt(bytes);
}
parameters.SetIntegerArray(entryName, array);
}
break;
case Parameters.EntryType.LONG_ARRAY:
{
int arrayLength = consumeInt(bytes);
long[] array = new long[arrayLength];
for(int j = 0; j != arrayLength; ++j)
{
array[j] = consumeLong(bytes);
}
parameters.SetLongArray(entryName, array);
}
break;
case Parameters.EntryType.DOUBLE_ARRAY:
{
int arrayLength = consumeInt(bytes);
double[] array = new double[arrayLength];
for(int j = 0; j != arrayLength; ++j)
{
array[j] = consumeDouble(bytes);
}
parameters.SetDoubleArray(entryName, array);
}
break;
case Parameters.EntryType.STRING_ARRAY:
{
int arrayLength = consumeInt(bytes);
string[] array = new string[arrayLength];
for(int j = 0; j != arrayLength; ++j)
{
array[j] = consumeString(bytes);
}
parameters.SetStringArray(entryName, array);
}
break;
case Parameters.EntryType.BINARY_ARRAY:
{
int arrayLength = consumeInt(bytes);
byte[][] array = new byte[arrayLength][];
for(int j = 0; j != arrayLength; ++j)
{
array[j] = consumeBinary(bytes);
}
parameters.SetBinaryArray(entryName, array);
}
break;
case Parameters.EntryType.NESTED_PARAMETERS:
{
Parameters nested = new Parameters();
deserializeFromBytes(nested, bytes);
parameters.SetNestedParameters(entryName, nested);
}
break;
}
}
}
示例3: 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");
}
//.........这里部分代码省略.........