i want this:
"collection": {
"id": "89999999",
"amount": "104",
"dateCreated": "2022-01-01"
}
to become this
"collection": [
"id: 89999999",
"amount: 104",
"dateCreated: 2022-01-01"
]
ive tried
((IEnumerable)obj).Cast<object>().Select(x => x.ToString()).ToArray()
but it crashes with the message "Unable to cast type "myobject" to IEnumerable"
any idea on how to proceed? or how to somehow convert a object/model to an array, specifically an string array, like the example above?
SOLVED
added this method to my class
public string[] ConvertToStringArray()
{
List<string> lst = new List<string>();
foreach (var prop in this.GetType().GetProperties())
{
if(prop.GetValue(this) != null)
{
lst.Add(prop.Name + ": " + prop.GetValue(this));
}
}
return lst.ToArray();
}
and then, just
obj.ConvertToStringArray()