createInstanceWithConstructors method
O?
createInstanceWithConstructors(
- List<
ConstructorReflection< constructors,O> > - Map<
String, Object?> map, { - FieldNameResolver? fieldNameResolver,
- FieldValueResolver? fieldValueResolver,
Creates an instance with one of the constructors
,
using map
entries as parameters.
- Throws UnresolvedParameterError when it's its impossible to call any constructor due to unresolved parameters.
- Throws any error thrown by a constructor invocation.
Implementation
O? createInstanceWithConstructors(
List<ConstructorReflection<O>> constructors,
Map<String, Object?> map, {
FieldNameResolver? fieldNameResolver,
FieldValueResolver? fieldValueResolver,
}) {
final length = constructors.length;
if (length == 0) {
return null;
} else if (length == 1) {
return _createInstanceWithConstructorImpl(constructors.first, map,
fieldNameResolver: fieldNameResolver,
fieldValueResolver: fieldValueResolver);
} else if (constructors is ListSortedByUsage<ConstructorReflection<O>>) {
var sorted = constructors.sortedByUsage();
var ret = _createInstanceWithConstructorsImpl(sorted, map,
fieldNameResolver: fieldNameResolver,
fieldValueResolver: fieldValueResolver);
if (ret != null) {
constructors.notifyUsage(ret.$1);
return ret.$2;
}
return null;
} else {
var ret = _createInstanceWithConstructorsImpl(constructors, map,
fieldNameResolver: fieldNameResolver,
fieldValueResolver: fieldValueResolver);
return ret?.$2;
}
}