i have three methods like these:
(我有三种这样的方法:)
func1() async {
...
var list = (response['contents'] as List).map((i) => Quotation.fromJson(i)).toList();
...
} // has 20 lines
func2() async {
...
var list = (response['contents'] as List).map((i) => Delivery.fromJson(i)).toList();
...
} // has 20 lines
func3() async {
...
var list = (response['contents'] as List).map((i) => Discovery.fromJson(i)).toList();
...
} // has 20 lines
now i would like to add a parameter to generalize the SomeClass.fromJson(i)
(现在我想添加一个参数来概括SomeClass.fromJson(i)
)
so the code would be like this
(所以代码会像这样)
generalFunc( someType SomeClass ) async {
...
var list = (response['contents'] as List).map((i) => SomeClass.fromJson(i)).toList();
...
}
... call generalFunc(Quotation) // reduce 19 lines
... call generalFunc(Delivery) // reduce 19 lines
... call generalFunc(Discovery) //reduce 19 lines
how do i accomplish this?
(我该如何做到这一点?)
thank you.. (谢谢..)
ask by nashihu translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…