I would like to split up the code responsible for unit conversion and ToString.
Since we have the ToUnit method, we could simplify the ToString implementations and implement IFormattable.
This would leave the following ToString overloads:
publicoverridestringToString();publicstringToString(stringformat);publicstringToString(IFormatProviderprovider);publicstringToString(stringformat,IFormatProviderprovider);
For example to get a length string in inches, we currently do the following:
varlength=Length.FromMeters(3.0);varlengthInInchesString=length.ToString(LengthUnit.Inch);
Today, this will achieve the same thing
varlength=Length.FromMeters(3.0);varlengthInInchesString=length.ToUnit(LengthUnit.Inch).ToString();
We could even change the conversion properties to return a converted quantity rather than a double (public Length Inches in this example) and do the following:
varlength=Length.FromMeters(3.0);varlengthInInchesString=length.Inches.ToString();
I would like to split up the code responsible for unit conversion and ToString.
Since we have the ToUnit method, we could simplify the ToString implementations and implement IFormattable.
This would leave the following ToString overloads:
For example to get a length string in inches, we currently do the following:
Today, this will achieve the same thing
We could even change the conversion properties to return a converted quantity rather than a double (public Length Inches in this example) and do the following: