getEntityID<O> method

  1. @override
Object? getEntityID<O>(
  1. O object, {
  2. Type? type,
  3. dynamic idGetter(
    1. O o
    )?,
})
override

Returns the ID value from object for type.

Implementation

@override
Object? getEntityID<O>(O object,
    {Type? type, dynamic Function(O o)? idGetter}) {
  if (object == null) return null;

  if (idGetter != null) {
    return idGetter(object);
  }

  type ??= object.runtimeType;

  var classReflection = ReflectionFactory().getRegisterClassReflection(type);

  if (classReflection != null) {
    var fieldID = classReflection
        .fieldsWhere((f) => f.name.toLowerCase() == 'id')
        .firstOrNull;
    fieldID ??=
        classReflection.fieldsWhere((f) => f.type.isIntType).firstOrNull;

    return fieldID?.withObject(object).get();
  }

  return null;
}