Inspirel banner

Programming Distributed Systems with YAMI4

3.6.4 .NET

Reading existing entries of fundamental types is straightforward:

int age = params.GetInteger("age");

Strings can be similarly extracted with a single function call:

string firstName = params.GetString("first_name");

Binary buffers are handled with the byte[] type:

byte[] songBuffer = params.GetBinary("favorite_song");

It should be noted that when reading the binary entry, the data is not cloned and no additional buffer is allocated - the above example returns a reference to the internal buffer.

Extracting arrays of fundamental types is very similar to handling of binary buffers - a reference to the internal array buffer is returned. Arrays of boolean, integer, long, double, string and binary types are handled in the same way and in all these cases the user gets access to the internally managed array buffers.

For example:

int[] myNumbers = params.GetIntegerArray("favorite_numbers");
string[] friends = params.GetStringArray("friends");

Nested parameters can be extracted in a similar way:

Parameters nested = params.GetNestedParameters("address");

Note:

If the entry given by name does not exist, each of the reading functions will throw the NoSuchNameException. Similarly, when the given entry exists but its type does not correspond to the expected type of the reading function, the BadTypeException will be thrown. Both exceptions inherit from ExceptionBase type, which is rooted in the standard System.Exception hierarchy. Code that needs to read entries that might not exist or with flexibility in type handling should use the methods described in later sections devoted to entry searches.