tryGetEnum<T extends Enum> method

T? tryGetEnum<T extends Enum>(
  1. K key, {
  2. required T parser(
    1. dynamic
    ),
  3. List<K>? alternativeKeys,
  4. dynamic innerKey,
  5. int? innerListIndex,
  6. T? defaultValue,
  7. Map<String, dynamic>? debugInfo,
})

Tries to convert the value at key (or alternativeKeys) to an enum using parser.

Implementation

T? tryGetEnum<T extends Enum>(
  K key, {
  required T Function(dynamic) parser,
  List<K>? alternativeKeys,
  dynamic innerKey,
  int? innerListIndex,
  T? defaultValue,
  Map<String, dynamic>? debugInfo,
}) {
  final info = <String, dynamic>{};
  if (debugInfo != null && debugInfo.isNotEmpty) {
    info.addAll(debugInfo);
  }
  info['key'] = key;
  if (alternativeKeys != null && alternativeKeys.isNotEmpty) {
    info['altKeys'] = alternativeKeys;
  }
  return ConvertObjectImpl.tryToEnum<T>(
    _firstValueForKeys(key, alternativeKeys: alternativeKeys),
    parser: parser,
    mapKey: innerKey,
    listIndex: innerListIndex,
    defaultValue: defaultValue,
    debugInfo: info,
  );
}