mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 08:07:11 +00:00
bbeda37c05
Change-Id: Ia137c8c139e13cb9b3f8017328f5a79edfcbc0b2 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151022 Reviewed-by: Sigmund Cherem <sigmund@google.com> Commit-Queue: Stephen Adams <sra@google.com>
37 lines
975 B
Dart
37 lines
975 B
Dart
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
class ComponentFactory<T> {
|
|
@pragma('dart2js:noInline')
|
|
Type get componentType => T;
|
|
}
|
|
|
|
var mm = {'String': String, 'int': int};
|
|
var gf1 = ComponentFactory<int>();
|
|
var gf2 = ComponentFactory<dynamic>();
|
|
Map<String, ComponentFactory> mf = {'RegExp': ComponentFactory<RegExp>()};
|
|
|
|
ComponentFactory test(String s, [Map<String, ComponentFactory> mf2]) {
|
|
var f = mf[s];
|
|
if (f == null) {
|
|
var t = mm[s];
|
|
if (mf2 != null) f = mf2[s];
|
|
if (t != null && t != f?.componentType) {
|
|
print('not match $t');
|
|
f = gf2;
|
|
}
|
|
}
|
|
return f;
|
|
}
|
|
|
|
main() {
|
|
Map<String, ComponentFactory> mf2 = {'int': ComponentFactory<num>()};
|
|
|
|
test('String');
|
|
test('String', mf2);
|
|
test('int');
|
|
test('int', mf2);
|
|
test('RegExp');
|
|
test('RegExp', mf2);
|
|
}
|