lundi 31 août 2020

How to get the original types of the properties of a reflected class?

After trying several ways to get to know about the original types of the classproperties from a reflected class. For example, this is an Animator class and Animator has four properties with it (id, name, costPerHour and reviews)

class Animator {
    int id;
    String name;    
    double costPerHour;
    List<Review> reviews;
}

...And from the Animator class, I wanna loop through the properties and I also wanna know if for example the original type of id (is id an int, a String or an object?).

With the discovery that declarations doesn't give the needed information in this situation;

var _refClass = reflectClass(Animator);
var classProperties = _refClass.declarations.values.forEach((property) => {
     // property.runtimeType returns only _DeclarationMirror of _propertyname_ 
}); // What is the original type each property??

Help is really appreceated, thanks.





Aucun commentaire:

Enregistrer un commentaire