void readFromMap(Map<String, dynamic> items)

Source

void readFromMap(Map<String, dynamic> items) {
  var reflectedThis = reflect(this);
  var properties = new List<String>();

  _variableDeclarations(reflectedThis.type).forEach((variableMirror) {
    String propertyName = MirrorSystem.getName(variableMirror.simpleName);
    properties.add(propertyName);

    var value = items[propertyName];

    if (value != null) {
      _readConfigurationItem(variableMirror, value);
    } else if (_isVariableRequired(variableMirror)) {
      throw new ConfigurationException("${propertyName} is required but was not found in configuration.");
    }
  });
  // validation of properties values
  List<String> validationErrors = validate();
  if (validationErrors.length > 0) {
    throw new ConfigurationException("${this.runtimeType} invalid property: $validationErrors");
  }

  var unexpectedKeys = items.keys.where((key) => !properties.contains(key));

  if (unexpectedKeys.length > 0) {
    throw new ConfigurationException("${this.runtimeType} contained unexpected keys: ${unexpectedKeys.join(", ")}");
  }
}