In previous example, Value.strdup_contents prints GLib.DateTime as pointer address. You can register functions that will transform value to desired type. First, create a function that will have this signature :
static void datetime_to_string (Value src_value, ref Value dest_value) {
DateTime dt = (DateTime)src_value;
dest_value.set_string (dt.to_string());
}
then register this function with Value.register_transform_func :
Value.register_transform_func (typeof (DateTime), typeof (string), datetime_to_string);
now GObject can convert any DateTime object to string value.
the complete example :
static void datetime_to_string (Value src_value, ref Value dest_value) {
DateTime dt = (DateTime)src_value;
dest_value.set_string (dt.to_string());
}
static void print_value (Value val) {
print ("value-type : %s\n", val.type().name());
print ("value-content : %s\n\n", val.strdup_contents());
}
public static void main (string[] args) {
print_value (new DateTime.now_local());
Value.register_transform_func (typeof (DateTime), typeof (string), datetime_to_string);
print_value (new DateTime.now_local());
}
value-type : GDateTime
value-content : ((GDateTime*) 0x560337def040)
value-type : GDateTime
value-content : 2017-04-20T18:40:20+0200