-
Notifications
You must be signed in to change notification settings - Fork 20
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
Add options to define arithmetic operators separately #30
Conversation
public static Hp operator -(in Hp x, in Hp y) => new Hp(checked((int)(x.value - y.value))); | ||
public static Hp operator *(in Hp x, in Hp y) => new Hp(checked((int)(x.value * y.value))); | ||
public static Hp operator /(in Hp x, in Hp y) => new Hp(checked((int)(x.value / y.value))); | ||
public static Hp operator +(Hp x, Hp y) => new Hp(checked((int)(x.value + y.value))); |
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.
The in
modifiers was removed because it could not comply with interfaces such as INumber<>.
src/UnitGenerator/SourceGenerator.cs
Outdated
|
||
public static bool TryConvertFromChecked<TOther>(TOther value, out {{unitTypeName}} result) where TOther : INumberBase<TOther> | ||
{ | ||
throw new NotSupportedException(); |
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.
The methods ofTryConvert*
family are in INumberBase<T>
but cannot be called because they are protected. I compromised and made it NotSupported....
Please let me know if you have a better way.
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.
Fixed implementation to return false
.
System.Numerics.INumber<T>
, and more options to specify operators individually.
thank you! ok to merge! |
80511ed
to
4670481
Compare
EDIT:
INumber<T>
implementation was stopped.IfUnitGenerateOptions.ArithmeticOperator
is specified, make sure that all members conforming toINumber<T>
are created by default.This allows UnitOf generated types to take advantage of features supported by Generic math. NET8 or later, for example, LINQ's aggregate would be available.Add extra option
UnitArithmeticOperators
UnitArithmeticOperators
enum to allow specifying the individual arithmetic operators to be generated.IAdditionalOperators<>
, which was added in .Breaking Changes
operator ++
,operator--
generation conditionsUnitGenerateOptions.ValueArithmeticOperator
UnitGenerateOptions.ArithmeticOperator
, withUnitArithmeticOperators.Number
(default) or.Increment
/.Decrement
UnitOf
arguments[UnitOf(..., ArithmeticOperator = ...]
toStringFormat
is changed to a named parameter from 3rd argument.