本文整理汇总了C#中Parameters.SetLong方法的典型用法代码示例。如果您正苦于以下问题:C# Parameters.SetLong方法的具体用法?C# Parameters.SetLong怎么用?C# Parameters.SetLong使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parameters
的用法示例。
在下文中一共展示了Parameters.SetLong方法的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: testForLong
public void testForLong()
{
parameters.SetLong("name", 1234567890L);
Assert.IsTrue(parameters.Count == 1);
Parameters.EntryType t = parameters.GetType("name");
Assert.AreEqual(t, Parameters.EntryType.LONG);
Assert.IsTrue(parameters.GetLong("name") == 1234567890L);
long[] array = { 100L, 200L, 300L };
parameters.SetLongArray("nameA", array);
Assert.IsTrue(parameters.Count == 2);
Assert.AreEqual(parameters.GetType("nameA"),
Parameters.EntryType.LONG_ARRAY);
Assert.AreEqual(parameters.GetLongArray("nameA"), array);
Assert.IsTrue(array.Length == 3);
Assert.IsTrue(
array[0] == 100L && array[1] == 200L && array[2] == 300L);
array[2] = 310L;
IEnumerator<Parameters.Entry> it = parameters.GetEnumerator();
Assert.IsTrue(it.MoveNext());
Parameters.Entry e = it.Current;
Assert.AreEqual(e.Type, Parameters.EntryType.LONG);
Assert.AreEqual("name", e.Name);
Assert.IsTrue(e.GetLong() == 1234567890L);
Assert.IsTrue(it.MoveNext());
e = it.Current;
Assert.AreEqual(e.Type, Parameters.EntryType.LONG_ARRAY);
Assert.AreEqual("nameA", e.Name);
Assert.AreEqual(e.GetLongArray(), array);
Assert.IsTrue(array.Length == 3);
Assert.IsTrue(
array[0] == 100L && array[1] == 200L && array[2] == 310L);
Assert.IsFalse(it.MoveNext());
Assert.AreEqual("entry 0:\n"
+ "name: name\n"
+ "long: 1234567890\n"
+ "entry 1:\n"
+ "name: nameA\n"
+ "long array: 100 200 310\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',
3, 0, 0, 0, // type code for long long
(byte) 210, 2, (byte) 150, 73, // 1234567890
0, 0, 0, 0,
5, 0, 0, 0, // length of "nameA"
(byte)'n', (byte)'a', (byte)'m', (byte)'e',
(byte)'A', 0, 0, 0,
9, 0, 0, 0, // type code for long long array
3, 0, 0, 0, // length of array
100, 0, 0, 0, // array values
0, 0, 0, 0,
(byte) 200, 0, 0, 0, // array values
0, 0, 0, 0,
54, 1, 0, 0, // array values
0, 0, 0, 0
};
checkSerialization(parameters, expected);
// additional test for bit extension bug
parameters = new Parameters();
parameters.SetLong("a", (long)1 << 31);
expected = new byte[] {
1, 0, 0, 0, // num of entries
1, 0, 0, 0, // length of "a"
(byte)'a', 0, 0, 0,
3, 0, 0, 0, // type code for long long
0, 0, 0, (byte) 128,
0, 0, 0, 0
};
checkSerialization(parameters, expected);
}