Closed LeoBound closed 1 month ago
I want to create a SimpleMapper for my generic class, but the type parameter of this class is bounded. For example (modifying the GenericBox example):
class NumberBox<T extends num> { NumberBox(this.content); final T content; } class NumberBoxMapper extends SimpleMapper1<NumberBox> { const NumberBoxMapper(); @override NumberBox<T> decode<T>(dynamic value) { T content = MapperContainer.globals.fromValue<T>(value); return NumberBox<T>(content); } @override dynamic encode<T>(NumberBox<T> self) { return MapperContainer.globals.toValue<T>(self.content); } @override Function get typeFactory => <T>(f) => f<NumberBox<T>>(); }
is invalid as the type bounds of encode and decode are unrestricted.
Is there a way around this, I was hoping I could make NumberBoxMapper generic e.g. NumberBoxMapper<T extends num>
NumberBoxMapper<T extends num
Thanks 🙂
I will add a SimpleMapper1Bounded for this.
SimpleMapper1Bounded
Added in v4.3.0
v4.3.0
I want to create a SimpleMapper for my generic class, but the type parameter of this class is bounded. For example (modifying the GenericBox example):
is invalid as the type bounds of encode and decode are unrestricted.
Is there a way around this, I was hoping I could make NumberBoxMapper generic e.g.
NumberBoxMapper<T extends num
>Thanks 🙂