XamarinAndroid:F#范围 – 如何在不同的文件中看到命名空间?

XamarinAndroid:F#范围 – 如何在不同的文件中看到命名空间?,第1张

概述Xamarin / Android:F#范围 – 如何在不同的文件中看到命名空间? 我知道这听起来很基本,但我似乎无法让它发挥作用.我将举例说明: 我开始一个新的解决方案,我选择一个新的F#Android应用程序并将其称为FSScopeTest1,给我MainActivity.fs namespace FSScopeTest1open Systemopen Android.Contentop Xamarin / Android:F#范围 – 如何在不同的文件中看到命名空间?

我知道这听起来很基本,但我似乎无法让它发挥作用.我将举例说明:

我开始一个新的解决方案,我选择一个新的F#AndroID应用程序并将其称为FSScopeTest1,给我MainActivity.fs

namespace FSScopeTest1open Systemopen AndroID.Contentopen AndroID.OSopen AndroID.Runtimeopen AndroID.VIEwsopen AdroID.Widget[<Activity (Label = "FSScopeTest1",MainLauncher = true)>]type MainActivity () =    inherit Activity ()    let mutable count:int = 1    overrIDe this.OnCreate (bundle) =        base.OnCreate (bundle)        // Set our vIEw from the "main" layout resource        this.SetContentVIEw (Resource_Layout.Main)        // Get our button from the layout resource,and attach an event to it        let button = this.FindVIEwByID<button>(Resource_ID.mybutton)        button.Click.Add (fun args ->            button.Text <- sprintf "%d clicks" count            count <- count + 1        )

然后我添加一个新的F#源文件ScopeTestNS.fs

namespace ScopeTestNSmodule ScopeTestMod =    let astr = "some text"

然后我在第二行添加到MainActivity.fs:

open ScopeTestNS

并更改button.Click.Add的lamba表达式以进行读取

button.Click.Add (fun args ->            // button.Text <- sprintf "%d clicks!" count            // count <- count + 1            button.Text <- ScopeTestMod.astr        )

现在,当我构建解决方案时,我收到错误:

The namespace or module "ScopeTestMod" is not defined.

如何使我的命名空间ScopeTestNS在MainActivity.fs中可见,这样我可以看到我在那里定义的任何模块?

非常感谢,
罗斯

解决方法 f#编译器按特定顺序读取源文件(与c#编译器不同).您需要确保项目以正确的顺序包含文件,以便您可以访问其他文件中定义的模块.

根据Onorio Catenacci的评论编辑:

显然,Xamarin Studio中使用的F#绑定目前不支持重新排序F#项目中的文件(请参阅此github问题https://github.com/fsharp/fsharpbinding/issues/135).但是,.fsproj文件是简单的xml文件,可以使用文本编辑器进行编辑,以更改编译文件的顺序.

编辑编辑

显然,xamarin工作室中的F#addin现在允许拖放以重新排序文件(感谢@ 7sharp9进行更新)

总结

以上是内存溢出为你收集整理的Xamarin / Android:F#范围 – 如何在不同的文件中看到命名空间?全部内容,希望文章能够帮你解决Xamarin / Android:F#范围 – 如何在不同的文件中看到命名空间?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1129255.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存