Hi guys,Could anybody clarify is there any option to get exact Type from generic parameter?Something like that:T myFunc<T>(){Type type = typeof(T);}
I've tried to get T.runtimeType but this property contains only obfuscated js type...
In c# you can achieve this functionality with typeof()
Map<Type, Function> functions = <Type, Function>{int: ((int x) => x + 1),String: ((String x) => x + " one"),};foo(v) {for (Type type in functions.keys) {if (v.runtimeType == type) return functions[type](v);}throw "Unknown type, cannot process";}main() {print(foo(40)); // '41'.print(foo("Forty")); // 'Forty one'.}
--
For more ways to connect visit https://www.dartlang.org/community
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/52647731-1553-42e1-b918-d3c4bf440442%40dartlang.org.
Hi guys,Could anybody clarify is there any option to get exact Type from generic parameter?Something like that:T myFunc<T>(){Type type = typeof(T);}
T myFunc<T>(){Type type = T;}