有没有办法在单个[<clievent>]块上包含多个事件声明?

时间:2015-05-26 15:20:49

标签: events f# annotations

写作有点乏味:

let e1 = Event<_>()
let e... = Event<_>()
let en = Event<_>()

[<CLIEvent>]
member this.E1 = e1.Publish
[<CLIEvent>]
member this.E... = e....Publish
[<CLIEvent>]
member this.En = en.Publish

在代码中,我展示了如何为每个事件编写n [<CLIEvent>],1。

1 个答案:

答案 0 :(得分:3)

[<CLIEvent>]不是“块”,它是属性

属性会立即应用于成员,因此,您不能将相同的[<CLIEvent>]属性应用于多个成员。

但如果有帮助,你可以把它们放在同一条线上:

[<CLIEvent>] member this.E1 = e1.Publish
[<CLIEvent>] member this.E... = e....Publish
[<CLIEvent>] member this.En = en.Publish