如何获取有关飞镖课程的信息? [英] How to get information about the class in dart?

查看:58
本文介绍了如何获取有关飞镖课程的信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Java到dart,两者之间有很多相似之处,但是我想做的一件事是获取有关dart中的类的一些信息,例如实例变量,方法和构造函数,但我做不到.我不知道怎么办,就像在Java类 Class ,类 Package 和类 Method 中一样,它们只是自我的简单表示,而在dart中,我做不到找不到除类 Type 以外的任何类,它是一个空白类,运行 type.runTime 返回 _Type ,所以被卡在这里,试图用谷歌搜索它,但是所有我发现这是dart的oop基础,简而言之,如何在Dart中获得那些Java类的等效项?并预先感谢.

I'm coming from java to dart and there are a lot of similarity between the two but one thing am trying to do is to get some info about a class in dart like the instance variables , methods and constructors but I couldn't know how , i mean like in java class Class , class Package and class Method are simple presentation of them self but in dart i couldn't find any but class Type witch it's a blank class and running type.runTime returns _Type so am stuck here , tried to google it but all i found is the oop basics of dart , in short , How to get the equivalent of those java classes in Dart ? and thanks in advance .

推荐答案

您可以使用 dart:mirrors 包. ClassMirror类可能可以帮助您.

You can use the dart:mirrors package for those. ClassMirror class maybe help you on this.

  TestClass test = new TestClass();
  var im = reflect(test);
  print(im.type.declarations.values);
  print(im.type.location);
  print(im.type.qualifiedName);
  print(test.runtimeType.toString());

我认为会为您提供所需的数据.

Will give you the data you are looking for i think.

如果您尝试不进行初始化,则 var im = reflect(TestClass); 而不是已经初始化的对象.只是dart.core._Type,您只会得到

If you try without initialization var im = reflect(TestClass); instead of already init object. It is just dart.core._Type and you will get only

(MethodMirror on 'hashCode', MethodMirror on '_Type')
dart:core-patch/type_patch.dart:15
Symbol("dart.core._Type")

这篇关于如何获取有关飞镖课程的信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆