本文整理汇总了C#中Parameters.SetDouble方法的典型用法代码示例。如果您正苦于以下问题:C# Parameters.SetDouble方法的具体用法?C# Parameters.SetDouble怎么用?C# Parameters.SetDouble使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parameters
的用法示例。
在下文中一共展示了Parameters.SetDouble方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: deserializeFromBytes
private static void deserializeFromBytes(Parameters parameters,
ByteIterator bytes)
{
int numOfEntries = consumeInt(bytes);
for(int i = 0; i != numOfEntries; ++i)
{
string entryName = consumeString(bytes);
int typeCode = consumeInt(bytes);
Parameters.EntryType type = codeToType(typeCode);
switch(type)
{
case Parameters.EntryType.BOOLEAN:
{
int value = consumeInt(bytes);
parameters.SetBoolean(entryName, value != 0);
}
break;
case Parameters.EntryType.INTEGER:
{
int value = consumeInt(bytes);
parameters.SetInteger(entryName, value);
}
break;
case Parameters.EntryType.LONG:
{
long value = consumeLong(bytes);
parameters.SetLong(entryName, value);
}
break;
case Parameters.EntryType.DOUBLE:
{
double value = consumeDouble(bytes);
parameters.SetDouble(entryName, value);
}
break;
case Parameters.EntryType.STRING:
{
string value = consumeString(bytes);
parameters.SetString(entryName, value);
}
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)
//.........这里部分代码省略.........
示例2: 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"
//.........这里部分代码省略.........