Questions tagged [dart-mirrors]

Dart Mirrors lets you reflect objects with an API that is based on the concept of mirrors.

Dart Mirrors lets you reflect objects with an API that is based on the concept of mirrors.

To use reflection on an object, you need to get a mirror for it first.

An introducion into Dart Mirrors.

dart:mirrors library

169 questions
214
votes
10 answers

How to perform runtime type checking in Dart?

Dart specification states: Reified type information reflects the types of objects at runtime and may always be queried by dynamic typechecking constructs (the analogs of instanceOf, casts, typecase etc. in other languages). Sounds great, but…
Volo
  • 28,673
  • 12
  • 97
  • 125
43
votes
3 answers

How to tell if an object is an instance of a class

How can I determine whether an object is of a class or not in the Dart language? I'm looking to do something like the following: if (someObject.class.toString() == "Num") { ... } And what is the returned value type? Will it have to be a…
george koller
  • 3,721
  • 6
  • 23
  • 27
29
votes
5 answers

REPL for the Dart language

Is there a REPL for Dart to experiment with? I tried inputing dart code in DevTools in Dartium and that also didn't work. So I couldn't find an easy way to play with various APIs in dart.
ducky
  • 1,113
  • 1
  • 11
  • 23
19
votes
3 answers

Passing a class type as a variable in Dart

It is possible to pass a class type as a variable in Dart ? I am trying to do something as follows: class Dodo { void hello() { print("hello dodo"); } } void main() { var a = Dodo; var b = new a(); b.hello(); } in python similar code…
rodrigob
  • 2,891
  • 3
  • 30
  • 34
15
votes
3 answers

Dynamic class method invocation in Dart

Like the question at Dynamic class method invocation in PHP I want to do this in Dart. var = "name"; page.${var} = value; page.save(); Is that possible?
samer.ali
  • 396
  • 2
  • 3
  • 11
14
votes
3 answers

What is the difference between Mirror based reflection and traditional reflection?

Some languages like Dart use mirror based reflection so, in simple terms, what is the difference between such implementation and traditional reflection as you see in C# or Java. Update: I found this excellent (and somewhat quirky) video by Gilad…
13
votes
1 answer

How do I access metadata annotations from a class?

I have a Dart class that is annotated with metadata: class Awesome { final String msg; const Awesome(this.msg); String toString() => msg; } @Awesome('it works!') class Cool { } I want to see if Cool was annotated, and if so, with what. How…
Seth Ladd
  • 112,095
  • 66
  • 196
  • 279
11
votes
4 answers

Instantiate a class from a string

In dart is it possible to instantiate a class from a string? For example: vanilla in javascript: var myObject = window[classNameString]; Objective-C: id myclass = [[NSClassFromString(@"MyClass") alloc] init];
1dayitwillmake
  • 2,269
  • 3
  • 26
  • 35
9
votes
3 answers

Create an instance of an object from a String in Dart?

How would I do the Dart equivalent of this Java code? Class c = Class.forName("mypackage.MyClass"); Constructor cons = c.getConstructor(String.class); Object object = cons.newInstance("MyAttributeValue"); (From Jeff Gardner)
Seth Ladd
  • 112,095
  • 66
  • 196
  • 279
9
votes
2 answers

How do I get all fields for a class in Dart?

I looked at the dart:mirrors library, and I found ClassMirror. While I saw getField I didn't see access to all fields. I did see getters, though. If I want to get all fields for a class, do I have to go through getters ?
Seth Ladd
  • 112,095
  • 66
  • 196
  • 279
9
votes
1 answer

Find all subclasses in dart

I have three classes in dart: class A {} class B extends A{} class C extends A{} There is a way to get all subclasses from A? Edit: Thanks Alexandre Ardhuin your solution worked perfectly! I'm learning the dart i edited your code and put the…
lucianoshl
  • 93
  • 1
  • 5
9
votes
1 answer

How do I get the qualified name from a Type instance, in Dart?

I have a instance of Type, but I want its fully qualified name. How can I do this? I know I have to use Mirrors (Dart's reflection library).
Seth Ladd
  • 112,095
  • 66
  • 196
  • 279
8
votes
2 answers

in Dart, problems with static method when called from variable

have class Klass with static method fn1 class Klass { static String fn1() => 'hello'; } > Klass.fn1(); // hello but when Klass is assigned to a variable, calling the method fn1 fails var k = Klass; > k.fn1() // "Unhandled exception: Class…
cc young
  • 18,939
  • 31
  • 90
  • 148
8
votes
1 answer

How can i test the existence of a function in Dart?

Is there a way to test the existence of a function or method in Dart without trying to call it and catch a NoSuchMethodError error? I am looking for something like if (exists("func_name")){...} to test whether a function…
7
votes
1 answer

How to add key value-pair to a Object?

I want to update my Object by adding a more key-value pair. Object options = { "first_name": "Nitish", "last_name" : "Singh" } after initializing the Object I want to add one more key and value. Is there any way to do this. after adding one…
nitishk72
  • 1,616
  • 3
  • 12
  • 21
1
2 3
11 12