-
Notifications
You must be signed in to change notification settings - Fork 387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update the ToString format of the BaseUnits/Dimensions #1486
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();
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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=Second
BaseDimensions
: 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
QuantityInfo
construction)