14.4. Annotations¶
DynamicTypeBuilder allows applying an annotation to both current type and inner members with the functions:
apply_annotation()
apply_annotation_to_member()
Both functions take the name, the key and the value of the annotation.
apply_annotation_to_member()
additionally receives the MemberId
of the inner member.
For example, if we define an annotation like:
@annotation MyAnnotation
{
long value;
string name;
};
And then we apply it through IDL to a struct:
@MyAnnotation(5, "length")
struct MyStruct
{
// ...
}
The equivalent code using DynamicType will be:
// Apply the annotation
DynamicTypeBuilder_ptr builder = DynamicTypeBuilderFactory::get_instance()->create_struct_builder();
//...
builder->apply_annotation("MyAnnotation", "value", "5");
builder->apply_annotation("MyAnnotation", "name", "length");