Example
The IDL (UniEnu.idl):
module UniEnu
{
enum property { surname, address, age, female};
union uniProperty switch (property)
{
case surname : string strSurname;
case address : string strAddress;
case age : long iAge;
case female : boolean bFemale;
};
interface Personal
{
void queryByName( in string strName, in property oPropIn, out uniProperty oPropOut);
};
};
(Will be compiled into UniEnu.cs)
The Implementation (ServerImpl.cs):
Since all declared data types are completely generated, we only have to implement the interface 'Personal':
public class PersonalImpl: UniEnu.PersonalPOA
{
public override void queryByName( string a_strName, UniEnu.property a_oProp, out UniEnu.uniProperty a_oPropOut )
{
a_oPropOut = new UniEnu.uniProperty();
switch( a_oProp )
{
case UniEnu.property.surname:
a_oPropOut.strSurname = a_strName + ", Dummy";
break;
case UniEnu.property.address:
a_oPropOut.strAddress = "Hamburg";
break;
case UniEnu.property.age:
a_oPropOut.iAge = 39;
break;
case UniEnu.property.female:
a_oPropOut.bFemale = false;
break;
}
}
}
The 'queryByName()' method illustrates the use of unions:
Depending on the discriminator of the union passed into the method 'queryByName()'
a newly created union instance is filled with data. The newly created union is
then pushed back through an IDL 'out' parameter.
The Client (ClientImpl.cs):
The client retrieves this union instance from the server and evaluates it:
UniEnu.uniProperty ouniProperty;
for( UniEnu.property i = UniEnu.property.surname; i <= UniEnu.property.female; i++)
{
oPersonal.queryByName("Hans", i, out ouniProperty);
switch( ouniProperty.discriminator)
{
case UniEnu.property.surname:
srLog += "\n Surname:" + ouniProperty.strSurname;
break;
case UniEnu.property.address:
srLog += "\n Address:"+ ouniProperty.strAddress;
break;
case UniEnu.property.age:
srLog += "\n Age:"+ ouniProperty.iAge;
break;
case UniEnu.property.female:
srLog += "\n Sex:"+ (ouniProperty.bFemale ?"Female":"Male");
break;
}
}