I've stumbled upon the fact that it's possible to define custom operators in F#. Also, I believe it's possible to reuse F# code in C#.
我偶然发现可以在F#中定义自定义运算符这一事实。另外,我相信可以在C#中重用F#代码。
Is it possible to create a custom operator in F#, reference the project in C# and then reuse the operator in C#? For example, lets say I were to define the .?
operator as something in F#, could I then somehow reuse it in my C# projects?
是否可以在F#中创建自定义运算符,在C#中引用项目,然后在C#中重用运算符?例如,假设我要定义。?运算符作为F#中的东西,我可以在C#项目中以某种方式重用它吗?
1 个解决方案
#1
16
Custom defined operators can be used just fine from C#. The names are auto-generated and are of the form op_<symbol...>
(see Overloaded Operator Names on MSDN).
自定义运算符可以在C#中正常使用。这些名称是自动生成的,格式为op_
For example
let (|?) a b = ...
would be available as op_BarQmark
.
将作为op_BarQmark提供。
However, as Mau points out in his comment, you will only be able to use it from C# as a method, not an operator.
但是,正如Mau在评论中指出的那样,你只能将它从C#用作方法,而不是操作符。
#1
16
Custom defined operators can be used just fine from C#. The names are auto-generated and are of the form op_<symbol...>
(see Overloaded Operator Names on MSDN).
自定义运算符可以在C#中正常使用。这些名称是自动生成的,格式为op_
For example
let (|?) a b = ...
would be available as op_BarQmark
.
将作为op_BarQmark提供。
However, as Mau points out in his comment, you will only be able to use it from C# as a method, not an operator.
但是,正如Mau在评论中指出的那样,你只能将它从C#用作方法,而不是操作符。