Dart 有python的等价物吗';s dir()在飞镖上?
正如标题所说,在dart上是否有python的Dart 有python的等价物吗';s dir()在飞镖上?,dart,dart-mirrors,Dart,Dart Mirrors,正如标题所说,在dart上是否有python的dir()等价物?python用于找出模块定义的名称 我们可以自己使用和编写一个等效函数(或至少非常类似): 导入“dart:mirrors”; 列表目录([String libraryName]){ 变量库,符号=[]; 如果(?libraryName){ lib=currentMirrorSystem().libraries[libraryName]; }否则{ lib=currentMirrorSystem().isolate.rootLibr
dir()
等价物?python用于找出模块定义的名称
我们可以自己使用和编写一个等效函数(或至少非常类似):
导入“dart:mirrors”;
列表目录([String libraryName]){
变量库,符号=[];
如果(?libraryName){
lib=currentMirrorSystem().libraries[libraryName];
}否则{
lib=currentMirrorSystem().isolate.rootLibrary;
}
lib.members.forEach((名称,镜像)=>symbols.add(名称));
返回符号;
}
下面是一个例子:
class Hello{}
bar()=>打印('yay');
main(){
var-foo=5;
打印(dir());//[main,bar,Hello,dir]
}
或指定一个库:
打印(dir('dart:mirrors');
[镜像错误,类型镜像,对象镜像,_LazyLibraryMirror,
TypeVariableMirror、MirrorException、ClassMirror、MirrorSystem、,
_LocalMirrorSystemImpl、\u LocalVMObjectMirrorImpl、DeclarationMirror、\u LazyTypeMirrorImpl、\u LocalClosureMirrorImpl、mirrorSystemOf、\u LazyFunctionTypeMirror、\u filterMap、MirroredCompiledError、\u Mirror、\u LocalClassMirrorImpl、\u LocalInstallanceMirrorImpl、\u LocalTypedefMirrorImpl、,
_LocalFunctionTypeMirrorImpl,reflect,MethodMirror,_LocalVariableMirrorImpl,LibraryMirror,_LocalSolateMirrorImpl,FunctionTypeMirror,_LocalLibraryMirrorImpl,Mirror,
_LocalObjectMirrorImpl、\u LocalMirrorImpl、\u MakeSignatureRestring、\u LocalTypeVariableMirrorImpl、Comment、MirroredUncaughtExceptionError、\u LocalParameterMirrorImpl、\u LazyTypeVariableMirror、TypedefMirror、VariableMirror、IsolateMirror、currentMirrorSystem、\u dartEscape、,
_LocalMethodMirrorImpl、ClosureMrror、VMReference、ParameterMirror、InstanceMirror、_isSimpleValue、SourceLocation]
这从字面上说明了特定库(模块)中定义的内容。现在Python的函数可能有些不同,它似乎也会对名称进行排序,但这应该给您一个领先的开始。Mirrors不可用。