简体   繁体   English

F#库在使用时应该表现得像C#

[英]F# library expected to behave like C# when consumed

I'm developing a library in F# for consumption by another team using C#. 我正在用F#开发一个库,供另一个使用C#的团队使用。 What things should I look out for knowing that this other team expects this library to behave like any other C# library? 我应该注意哪些事情知道其他团队希望这个库的行为与其他任何C#库一样?

For example if I use Options types I'll need to convert them to null when I expose to C#. 例如,如果我使用Options类型,当我向C#公开时,我需要将它们转换为null。 Some other possible transition areas could be computation expressions, FastFunc, events and naming issues. 其他一些可能的过渡区域可能是计算表达式,FastFunc,事件和命名问题。

F#组件设计指南是一个旨在回答这个问题的文档。

Make sure you don't expose any of the F# types, especially lists, maps, etc (exposing something of type Microsoft.FSharp.Collections.FSharpMap will surely make the C# team go nuts). 确保你没有公开任何F#类型,特别是列表,地图等(暴露某些类型的Microsoft.FSharp.Collections.FSharpMap肯定会让C#团队疯狂)。 When you're exposing a getter or a return type that is a F# collection, call List.toSeq and you'll end up with an IEnumerable , which is much nicer to work with in C#. 当你暴露一个getter或一个F#集合的返回类型时,调用List.toSeq ,你最终会得到一个IEnumerable ,这在C#中更好用。

Other than that, you should be just fine. 除此之外,你应该没问题。 I've used F# and C# on only 1 project before, and that was my only real issue/annoyance interoperating the two. 我之前只在1个项目中使用过F#和C#,这是我唯一真正的问题/烦恼,两者互操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM