mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 11:02:31 +00:00
b101a7d002
Change-Id: Ib33169c3e0ffc870915c189404074a1dea472546 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196548 Reviewed-by: Bob Nystrom <rnystrom@google.com> Commit-Queue: Leaf Petersen <leafp@google.com>
40 lines
991 B
Dart
40 lines
991 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.
|
|
|
|
// @dart = 2.9
|
|
|
|
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);
|
|
}
|