0

Tl; dr: I get the class symbol and arguments dynamically, how do I get the object and not some mirror thingy.

Hi,

I have a situation where I get the symbol (or string) of a class name and the arguments (maybe positional, maybe optional positional, or named). Can I do the following?

class SomeClass{
    SomeClass(String a, {int b: 3}) { /* someCode */ }
    // someContent
}

List someList = ["SomeClass", 'a', {"b": 5}];

SomeClass objectFromList = /* someFancyMagicHappensHere */;

Where someList comes from is of no relevance, it may be a from a simple List, from an XML or from outer space. I have some influence of the format of someList, so this may be changed to a map, contain symbols etc. I know i could write a factory for a number of cases but I am looking for a more general solution.

Is there someFancyMagic in Dart?

Cheers and Thanks

P.S.: If there is no fancyMagic, is there a specific reason? Is this regarded an antipattern? Is there a better approach? Is the language simply not made for it (yet)?

wellnoidea
  • 193
  • 10
  • 1
    I think this is basically what you are looking for http://stackoverflow.com/questions/14242712. See also http://stackoverflow.com/questions/25316086, http://stackoverflow.com/questions/17181108, http://stackoverflow.com/questions/19166146 – Günter Zöchbauer Nov 28 '14 at 21:41
  • \o/ Yay! Made a duplicate! Thanks for the quick answer though. [stackoverflow.com/questions/17181108](http://stackoverflow.com/questions/17181108) your answer did the trick, Günther. – wellnoidea Nov 28 '14 at 21:48

0 Answers0