I have a given type
and a Comma Separated Values string
:
Type type = service.getType();
String csv = "1,2,3";
I need to convert the csv
string to an IEnumerable
of type
.
I know that type
will be numeric, e.g., int
, short
, long
, etc.
I am able to spit the csv
and convert each one to given type
..
String[] inputs = csv.Split(',');
TypeConverter converter = TypeDescriptor.GetConverter(modelType);
if (converter != null) {
foreach (String input in inputs) {
if (converter.CanConvertTo(type)) {
var number = converter.ConvertFromString(input);
// Add number to an IEnumerable of numbers
}
}
}
I am not able to create an IEnumerable
of type
and add numbers to it.
How can I do this?