Search code examples
c#operator-overloadingboo

Operator overloading in Boo - op_NotEqual?


I have an old C# library that I am converting to Boo, and it uses operator overloading. In the interest of not to getting into the why of that, I am looking for a way do the same thing in Boo.

This takes the form:

public static bool operator <(Duration duration, TimeSpan timespan) {...}

But, Boo uses a different form of operator overloading, and does not have an 'operator' keyword.

public static def op_LessThan(duration as Duration, timespan as TimeSpan) as bool:
    pass

(From http://boo.codehaus.org/Operator+overloading)

These binary operators can be overloaded:

  • op_Addition
  • op_Subtraction
  • op_Multiply
  • op_Division
  • op_Modulus
  • op_Exponentiation
  • op_Equality
  • op_LessThan
  • op_LessThanOrEqual
  • op_GreaterThan
  • op_GreaterThanOrEqual
  • op_Match
  • op_NotMatch
  • op_Member
  • op_NotMember
  • op_BitwiseOr
  • op_BitwiseAnd

But I don't see anything like op_NotEqual(!=) in that list. Are these methods equivalent to the above C# code? And if so, what would be the equivalent of

public static bool operator !=(Duration duration, TimeSpan timespan) {...}

Solution

  • It should be op_Inequality (from the C#/.NET side) - but I don't know if or how this is supported in Boo. I suspect it's just a documentation error, and will likely work fine.