validateInProperty method
Implementation
String validateInProperty(String unit, String property) {
assert(unit.isNotEmpty,
paramError('validate', 'unit', 'must not be null or empty'));
assert(
property.isNotEmpty,
paramError(
'validateInProperty', 'property', 'must not be null or empty'));
try {
// Assuming Term, ExpressionParser, Converter, Canonical, ExpressionComposer are implemented in Dart
final Term term = ExpressionParser(model).parse(unit);
final Canonical can = Converter(model, handlers).convert(term);
final String cu = ExpressionComposer().composeCanonical(can, false);
if (can.units.length == 1) {
if (property == can.units[0].base.property) {
return '';
} else {
return 'unit $unit is of the property type ${can.units[0].base.property} ($cu), not $property as required.';
}
}
// Defined special case
if (property == 'concentration' && (cu == 'g/L' || cu == 'mol/L')) {
return '';
}
return 'unit $unit has the base units $cu, and are not from the property $property as required.';
} catch (e) {
return e.toString();
}
}