-
Notifications
You must be signed in to change notification settings - Fork 387
Adding operator overloads
Andreas Gullberg Larsen edited this page Feb 25, 2019
·
6 revisions
There is a large number of operator overloads, to facilitate strongly typed computations such as Speed speed = Length.FromMeters(100) / TimeSpan.FromSeconds(9);
.
- Put operator overload in
Length.extra.cs
if the first parameter isLength
- Add a short xmldoc summary as per the example below. You can add more descriptions if it is useful.
The reason is to have a consistent place to find the operator overloads and the compiler complains if the containing type/file does not match any of the parameters of the operator overload method.
/UnitsNet/CustomCode/Quantities/Length.extra.cs
/// <summary>Get <see cref="Speed"/> from <see cref="Length"/> divided by <see cref="TimeSpan"/>.</summary>
public static Speed operator /(Length length, TimeSpan timeSpan)
{
return Speed.FromMetersPerSecond(length.Meters/timeSpan.TotalSeconds);
}