You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// <summary>/// An <see cref="IQuantity{TUnitType}"/> that (in .NET 7+) implements generic math interfaces for equality, comparison and parsing./// </summary>/// <typeparam name="TSelf">The type itself, for the CRT pattern.</typeparam>/// <typeparam name="TUnitType">The underlying unit enum type.</typeparam>
#if NET7_0_OR_GREATERpublicinterfaceIQuantity<TSelf,TUnitType>:IQuantity<TUnitType>,IComparisonOperators<TSelf,TSelf,bool>,IParsable<TSelf>
#else
public interface IQuantity<in TSelf,TUnitType>: IQuantity<TUnitType>
#endif
whereTSelf:IQuantity<TSelf,TUnitType>whereTUnitType: Enum
I think that the IComparisonOperators<TSelf, TSelf, bool> and IParsable<TSelf> declarations should be moved to the implementation section.
The motivation: reduce the number of methods / operators required for the "custom quantities": consider how many methods are added by moving HowMuch from : IQuantity to : IQuantity<HowMuch, HowMuchUnit>.
A more theoretical motivation is that by having it on the interface, it feels like we're expressing a requirement, as in "I need this method in order to be able to do something"- which is clearly not the case here.
IMO anyone requiring the generic constraint can use a combination of constraints:
Note that repeating the declaration 180 times would add few KB to the size, but if that's a priority, we could introduce some IDefaultQuantity<TQuantity> interface and move all interface declarations that are shared by all quantities:
Note that repeating the declaration 180 times would add few KB to the size, but if that's a priority, we could introduce some IDefaultQuantity<TQuantity> interface and move all interface declarations that are shared by all quantities:
Hmm, weirdly enough, after removing it from the interface there was actually a decrease in size (~1KB).. (🤷 )
Yeah that makes sense I think, moving interfaces to implementations instead of requiring all IQuantity implementors to add all the same stuff. As long as there isn't some IQuantity-based code that expects this or that, you will find out soone enough I guess 😄
Here is the current declaration:
I think that the
IComparisonOperators<TSelf, TSelf, bool>
andIParsable<TSelf>
declarations should be moved to the implementation section.The motivation: reduce the number of methods / operators required for the "custom quantities": consider how many methods are added by moving
HowMuch
from: IQuantity
to: IQuantity<HowMuch, HowMuchUnit>
.A more theoretical motivation is that by having it on the interface, it feels like we're expressing a requirement, as in "I need this method in order to be able to do something"- which is clearly not the case here.
IMO anyone requiring the generic constraint can use a combination of constraints:
Note that repeating the declaration 180 times would add few KB to the size, but if that's a priority, we could introduce some
IDefaultQuantity<TQuantity>
interface and move all interface declarations that are shared by all quantities:The text was updated successfully, but these errors were encountered: