如果有Type
,使用Mirrors
可以获取Type
名称。相反,给定 aType
的名字,你如何得到Type
?
例如,来自以- 为中心的Dart
版本Angular
:
索引.html
<form ng-controller='word?reset=true' >
...
</form>
mylib.dart
class Controller {
Controller( Brando brando, Element elem, Map args ) { ... }
}
class Word extends Controller { ... }
class LangList extends Controller { ... }
// Brando, the godfather
class Brando {
...
void compile( Element el ) {
...
// add controller
if( el.attributes.contains( 'ng-controller' ) {
var name = el.attributes.getTypeName(); <== "Word"
var args = el.attributes.getTypeArgs(); <== { 'reset': 'true' }
var type = <get type from camelized Type name> <=== how??
this.controllers.add( reflectClass(type).newInstance(
const Symbol(''), [this,el,args]).reflectee ); <=== instance from type
}
...
}
}
知道如何获取名称Type
,如何Type
从class
and中获取Object
,并且知道如何实例化 a Type
。缺少最后一块 - 你是如何Type
从它的名字中得出的?