parsedValue property
dynamic
get
parsedValue
将DartObject转换为对应的Dart基础类型或Map(自定义类型)
Implementation
dynamic get parsedValue {
if (isNull) return null;
final type = this.type;
if (type == null) return _unknownValue(this);
// 基本类型处理
if (_boolChecker.isExactlyType(type)) {
return toBoolValue();
} else if (_intChecker.isExactlyType(type)) {
return toIntValue();
} else if (_doubleChecker.isExactlyType(type)) {
return toDoubleValue();
} else if (_stringChecker.isExactlyType(type)) {
return toStringValue();
} else if (_symbolChecker.isExactlyType(type)) {
return toSymbolValue();
}
// 列表类型处理
else if (_listChecker.isAssignableFromType(type)) {
return toListValue()?.map((item) => item.parsedValue).toList();
}
// Map类型处理
else if (_mapChecker.isAssignableFromType(type)) {
final map = toMapValue() ?? {};
return {
for (final entry in map.entries)
entry.key?.parsedValue: entry.value?.parsedValue,
};
}
// // 枚举类型处理(修正部分)
// else if (type.element is EnumElement) {
// return _parseEnum(this, type.element as EnumElement);
// }
// 类型字面量处理
else if (_typeChecker.isExactlyType(type)) {
return {
'__type': 'type',
'name': type.genericsName,
'isNull': type.nullabilitySuffix == NullabilitySuffix.question,
};
}
// 自定义对象处理
else if (type is InterfaceType) {
return _parseInterfaceType(this, type);
}
// 未知类型处理
return _unknownValue(this);
}