createParseCode static method
String
createParseCode(
- Property property, {
- String paramsName = "",
})
Implementation
static String createParseCode(Property property, {String paramsName = ""}) {
var isEmpty = property.canBeNull ? "?" : "";
var first = paramsName.isNotEmpty ? paramsName : "result";
if (property.type == "dart.core.List") {
// (result as List).map((e) => e as test(property.subType[0], e)).toList();
return "($first as List$isEmpty)$isEmpty.map((result) => ${createParseCode(property.subType[0])}).toList()";
} else if (property.type == "dart.core.Map") {
// (result as Map).map((e) => e as MapEntry(
// test(property.subType[0], e), test(property.subType[1], e))).toList();
return " ($first as Map$isEmpty)$isEmpty.map((key, value) => MapEntry(${createParseCode(property.subType[0], paramsName: "key")},${createParseCode(property.subType[1], paramsName: "value")}))";
} else if (TypeUtils.isBaseType(property) || isObject(property)) {
return " $first as ${TypeUtils.getPropertyNameStr(property)}$isEmpty ";
} else {
//custom class
if (property.canBeNull) {
return "$first != null ? ${TypeUtils.getPropertyNameStr(property)}.fromJson(jsonDecode($first.split(\"___custom___\")[1]))"
": null";
} else {
return "${TypeUtils.getPropertyNameStr(property)}.fromJson(jsonDecode($first.split(\"___custom___\")[1]))";
}
}
}