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

161 questions
135
votes
8 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…
Idolon
  • 26,581
  • 12
  • 93
  • 121
36
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
  • 2,363
  • 3
  • 17
  • 26
28
votes
4 answers

REPL for dartlang

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,072
  • 1
  • 10
  • 21
15
votes
2 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,699
  • 2
  • 27
  • 33
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
  • 77,313
  • 56
  • 165
  • 258
12
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
  • 356
  • 3
  • 11
10
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,110
  • 3
  • 22
  • 34
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
  • 77,313
  • 56
  • 165
  • 258
8
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
  • 77,313
  • 56
  • 165
  • 258
8
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
  • 83
  • 5
7
votes
1 answer

How can you make dynamic getters/setters in dart

I am trying to recreate djangos QueryDict functionality and make a object that can be given a Map and it be a private variable in the object and getters/setters are used to pull from the map dynamically. I have managed to recreate the get() method…
DigitalFiz
  • 494
  • 2
  • 15
7
votes
1 answer

Is there an equivalent of python's dir() on dart?

As the title says, is there an equivalent of python's dir() on dart?
Otskimanot Sqilal
  • 2,052
  • 2
  • 18
  • 24
7
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 get concrete object of a static method via mirror API?

I have something like this: class MyClass { static void DoSomething(arg1, arg2){...} } Via reflection, I am able to get the ClassMirror of this class. From this point, how would I get to the concrete static function so I can call it. Note that…
John Evans
  • 4,861
  • 1
  • 21
  • 23
1
2 3
10 11