Update the ToString format of the BaseUnits/Dimensions#1486
Update the ToString format of the BaseUnits/Dimensions#1486angularsen merged 2 commits intoangularsen:release/v6from
Conversation
- BaseUnits: no longer using the AbbeviationsCache - BaseDimensions: the exponent moved inside the dimension-brackets - BaseDimensions: minor performance improvements
|
@angularsen Happy new year, here's an easy one which we've talked about in #1452 I wasn't 100% sure back then (and I never actually meant for it to be optimal), but I did a quick benchmark and the public string ToStringWithAppend()
{
if (Equals(Undefined))
{
return "Undefined";
}
var sb = new StringBuilder();
if (Length is not null)
{
sb.Append("[Length]: ").Append(Length).Append(", ");
}
if (Mass is not null)
{
sb.Append("[Mass]: ").Append(Mass).Append(", ");
}
if (Time is not null)
{
sb.Append("[Time]: ").Append(Time).Append(", ");
}
if (Current is not null)
{
sb.Append("[Current]: ").Append(Current).Append(", ");
}
if (Temperature is not null)
{
sb.Append("[Temperature]: ").Append(Temperature).Append(", ");
}
if (Amount is not null)
{
sb.Append("[Amount]: ").Append(Amount).Append(", ");
}
if (LuminousIntensity is not null)
{
sb.Append("[LuminousIntensity]: ").Append(LuminousIntensity).Append(", ");
}
if (sb.Length > 2)
{
sb.Length -= 2; // Remove the trailing ", "
}
return sb.ToString();
} |
angularsen
left a comment
There was a problem hiding this comment.
Looks good to me, a couple of suggestions
I meant to answer and forgot, happy new year @lipchev 🎉 I'm very glad you are around to learn from, and discuss and share ideas with, I really appreciate it ❤️ |
BaseUnits: no longer using theAbbeviationsCache, the new format isL=Meter, M=Kilogram, T=SecondBaseDimensions: the exponent moved inside the dimension-brackets:[Length][Time^-1]BaseDimensions: minor performance improvementsAs mentioned in #1452, the main motivation here is the removal of the potential side effects of accessing/loading the unit abbreviations (e.g. during the
QuantityInfoconstruction)