// Works ClassMirror m1 = reflectClass(List); print(m1.newInstance(new Symbol(''), []));
// Does not work, reflectClass does not allow 'List<int>'// ClassMirror m2 = reflectClass(List<int>);// print(m2.newInstance(new Symbol(''), []));
// Does not work, No constructor '_GrowableList.' declared in class 'List'.// InstanceMirror m3 = reflect(new List());// print(m3.type.newInstance(new Symbol(''), []));
// Does not work, No constructor '_GrowableList.' declared in class 'List'.// InstanceMirror m4 = reflect(new List<int>());// print(m4.type.newInstance(new Symbol(''), []));
InstanceMirror m4 = reflect(new List<int>());
ClassMirror listOfInt = m4.type.superinterfaces[0]; // prints List, but it is really List<int>
print(listOfInt.typeArguments); // prints 'int'
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.
class TestClass { int value = 42;
}
InstanceMirror m4 = reflect(new List<int>()); ClassMirror listOfInt = m4.type.superinterfaces[0];
var l4 = listOfInt.newInstance(new Symbol(''), []).reflectee; print(l4.runtimeType);
InstanceMirror m5 = reflect(new List<TestClass>()); ClassMirror listOfTestClass = m5.type.superinterfaces[0]; var l5 = listOfTestClass.newInstance(new Symbol(''), []).reflectee; print(l5.runtimeType);
List<int>List<TestClass>
InstanceMirror im = reflect(new ListContainer()); ClassMirror mirror = im.type; TypeMirror tm = mirror.instanceMembers[#myList].returnType;
print(tm.reflectedType); print(tm.typeArguments);
// How can I create an instance of type [tm.reflectedType] here? //.....
class ListContainer { List<int> myList; }
List<int>[ClassMirror on 'int']
List<int> l = VaneModel.decode('[7, 8, 9]', new List<int>());
List<int> l = VaneModel.decode('{"l": [7, 8, 9]}', new Podo());
class Podo extends VaneModel {
List<int> l;
}
class Podo extends VaneModel {
List<int> = new List<int>();
}
"I have an instance of a type X and I need to reflectively create an instance of List<X>".
"I have an instance of a type 'Foo' that has a member 'List<Bar> list' and I need to reflectively instantiate 'list' as a List<Bar> list (using List<dynamic> is not considered good enough)".