当我在现有模块上声明命名空间时,我收到错误。
错误:
定义中结构化构造的意外启动。预期'=' 或其他令牌。
注意,我只是添加名称空间:
namespace ManageModules
没有命名空间,代码就会编译。
代码:
namespace ManageModules
module CreateModule.UILogic
open System.Windows.Input // Error is referenced here...
open UILogic.State
open UILogic.Interaction
open ManageModule.Entities
open System.Collections.ObjectModel
type CreationViewModel() =
inherit ViewModelBase()
let mutable (_modules:Module ObservableCollection) = ObservableCollection()
member this.Modules
with get() = _modules
and set(value) = _modules <- value
member this.Add moduleItem =
_modules.Add(moduleItem)
答案 0 :(得分:4)
有两种类型的模块声明:顶级模块声明和本地模块声明。
使用以下语法声明顶级模块声明:
module [accessibility-modifier] [qualified-namespace.]module-name
使用
声明本地模块声明module [accessibility-modifier] module-name =
顶级模块声明必须作为文件中的第一个语句出现,然后模块包含该文件中的所有内容。相比之下,您可以拥有多个本地模块声明。
请注意,虽然顶级声明还允许您选择添加.
来提供合格的命名空间,但是您可以在本地模块声明中使用.
,尽管您可以嵌套本地模块。
在您的情况下,由于您的模块声明未出现在文件的开头,您必须写:
namespace ManageModules
module CreateModule =
...
有关详细信息,请参阅https://msdn.microsoft.com/en-us/library/dd233221.aspx。
答案 1 :(得分:0)
看起来当我在模块上提供命名空间时,我需要在模块声明中附加一个相等的运算符。
namespace ManageModules
module CreateModule =
<强>代码:强>
namespace ManageModules
module CreateModule =
open System.Windows.Input
open UILogic.State
open UILogic.Interaction
open ManageModule.Entities
open System.Collections.ObjectModel
type CreationViewModel() =
inherit ViewModelBase()
let mutable (_modules:Module ObservableCollection) = ObservableCollection()
member this.Modules
with get() = _modules
and set(value) = _modules <- value
member this.Add moduleItem =
_modules.Add(moduleItem)