简体   繁体   English

在Xamarin的C#项目中使用F#库

[英]Using an F# library in a C# project in Xamarin

I have a solution in Xamarin Studio with a C# console program trying to call an F# library. 我在Xamarin Studio中有一个解决方案,它有一个C#控制台程序试图调用一个F#库。

The reference is fine, everything builds. 参考很好,一切都在建立。

My F# code looks like the following: 我的F#代码如下所示:

namespace MyStore.Library

module public Lookup =

    open System

    let lookup name (age:int) =
        String.Format("{0}, {1}", name, age.ToString() );

I can call the F# library from an F# console and a C# library from the C# console, but I can't mix the two. 我可以从F#控制台调用F#库,从C#控制台调用C#库,但我不能将它们混合在一起

The C# console doesn't see any F# namespaces at all. C#控制台根本看不到任何F#名称空间。

What am I doing wrong? 我究竟做错了什么?

What should I do to see the F# namespace from C#? 如何从C#查看F#名称空间?

In the C# project, you need to add a reference to your F# project. 在C#项目中,您需要添加对F#项目的引用。

In the Solution pane, expand your project, and click the gear icon -> Edit References 在“解决方案”窗格中,展开项目,然后单击齿轮图标 - >编辑参考

Then go to Projects tab, check the F# project you want to reference to, then click OK. 然后转到Projects选项卡,检查要引用的F#项目,然后单击OK。

编辑参考项目

Also, make sure both C# and F# project target to the same .NET framework! 另外,确保C#和F#项目都针对同一个.NET框架! To check that, right click a project, Options -> Build -> General 要检查这一点,请右键单击项目,选项 - >构建 - >常规

右键单击项目目标

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

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