Я пытаюсь получить тип переменных в runtim на языке дартс, когда у Моих полей в классе нет значения по умолчанию, например, int, String и т. Д., Я не могу получить тип поля, но когда я устанавливаю значение по умолчанию, это нормально.
В этом примере я хочу указать тип T и тип bool и string в моем классе:
class MessageContract<T>
{
T Data;
bool IsSuccess;
int IntValue;
}
class Product {
String Name = "";
int Age = 0;
}
тестовый пример:
MessageContract<Product> msg = new MessageContract<Product>();
var instanceMirror = reflect(msg);
var type = instanceMirror.type;
// type will be null for Object's superclass
while (type != null) {
// if you only care about public fields,
// check if d.isPrivate != true
for(var item in type.declarations.values)
{
if ( item is VariableMirror) {
print("ok:"+item.type.toString());
}
print(item);
}
type = type.superclass;
}