Boo 中的运算符重载 - op_NotEqual?
我有一个旧的 C# 库,我正在将其转换为 Boo,它使用运算符重载。为了不深究其原因,我正在寻找一种在 Boo 中做同样事情的方法。
其形式如下:
public static bool operator <(Duration duration, TimeSpan timespan) {...}
但是,Boo 使用不同形式的运算符重载,并且没有“operator”关键字。
public static def op_LessThan(duration as Duration, timespan as TimeSpan) as bool:
pass
(来自 http://boo.codehaus.org/Operator+overloading)
这些二元运算符可以是重载:
- 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
但我在该列表中没有看到类似 op_NotEqual(!=) 的内容。这些方法与上面的 C# 代码等效吗?如果是这样的话,相当于什么
public static bool operator !=(Duration duration, TimeSpan timespan) {...}
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) {...}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它应该是
op_Inequality
(来自 C#/.NET 端) - 但我不知道 Boo 是否或如何支持它。我怀疑这只是一个文档错误,并且可能会正常工作。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.