parseStruct method

dynamic parseStruct(
  1. dynamic description
)

Implementation

parseStruct(description) {
  if (description is Function) {
    // TODO js 方法是 参数长度可变
    // print(" description: ${description.runtimeType.toString()} ");

    String _fn = description.runtimeType.toString();

    if(_fn.startsWith("()")) {
      return description();
    } else if(_fn.startsWith("(dynamic)")) {
      return description(this);
    } else {
      return description(this, null);
    }
  } else {
    var fields = description.keys.toList();
    var struct = {};
    for (var j = 0; j < fields.length; j++) {
        var fieldName = fields[j];
        var fieldType = description[fieldName];

        String _fn = fieldType.runtimeType.toString();
        if(_fn.startsWith("()")) {
          struct[fieldName] = fieldType();
        } else if(_fn.startsWith("(dynamic)")) {
          struct[fieldName] = fieldType(this);
        } else {
          struct[fieldName] = fieldType(this, null);
        }

    }
    return struct;
  }
}