transformToList<T> function

List<T> transformToList<T>(
  1. Object? o
)

Implementation

List<T> transformToList<T>(Object? o) {
  if (o is List) {
    return o.map((e) => transformToType<T>(e)).whereType<T>().toList();
  } else if (o is T) {
    return <T>[o];
  } else if (o == null) {
    return <T>[];
  } else {
    var t = transformToType<T>(o);

    if (t == null) {
      if (o is String) {
        var l = parseFromInlineList(
            o.trim(),
            RegExp(r'\s*[;,]\s*', multiLine: false),
            (e) => transformToType<T>(e));
        return transformToList<T>(l);
      }
      return <T>[];
    } else {
      return <T>[t];
    }
  }
}