public static void Main(string[] args) { try { /* Creating the union typeCode */ DDS.TypeCodeFactory tcf = DDS.TypeCodeFactory.get_instance(); DDS.TypeCode unionTC = create_type_code(tcf); DDS.DynamicDataMemberInfo info = new DDS.DynamicDataMemberInfo(); DDS.DynamicDataProperty_t myProperty = DDS.DynamicData.DYNAMIC_DATA_PROPERTY_DEFAULT; short valueTestShort = 0; /* Creating a new dynamicData instance based on the union * type code */ DDS.DynamicData data = new DDS.DynamicData(unionTC, myProperty); /* If we get the current discriminator, it will be the default one * (not the first added) */ data.get_member_info_by_index(info, 0); Console.WriteLine("The member selected is {0}", info.member_name); /* When we set a value in one of the members of the union, * the discriminator updates automatically to point that member. */ data.set_short("aShort", DDS.DynamicData.MEMBER_ID_UNSPECIFIED, 42); /* The discriminator should now reflect the new situation */ data.get_member_info_by_index(info, 0); Console.WriteLine("The member selected is {0}", info.member_name); /* Getting the value of the target member */ valueTestShort = data.get_short("aShort", DDS.DynamicData.MEMBER_ID_UNSPECIFIED); Console.WriteLine("The member selected is {0} with value: {1}", info.member_name, valueTestShort); return; } catch (Exception e) { Console.WriteLine("register_type error {0}", e); return; } }