validate method

void validate()
inherited

Validate all Parameters to ensure that all required parameters are set Use this method to validate parameters during a function call

Implementation

void validate() {
  // Collect all properties for this class
  var propertiesAndMirror = _allPropertiesAndMirror(this);
  var properties = propertiesAndMirror.item1;
  var mirror = propertiesAndMirror.item2;

  // Check that all required parameters are set
  for (var property in properties) {
    // Get the parameter attribute for this property
    var parameterAttribute =
        CustomAnnotation.getAnnotationOfType<Parameter>(Parameter, property);
    // If the property is not a parameter, ignore it
    if (parameterAttribute == null) {
      continue;
    }

    // If the parameter is required and not set, throw an exception
    if (parameterAttribute.necessity == Necessity.required) {
      try {
        var value = mirror.invokeGetter(property.simpleName);
        if (value == null) {
          throw MissingParameterException.generate(property.simpleName);
        }
      } catch (e) {
        // If the property is not set, ignore it
        continue;
      }
    }
  }
}