1
如何在C#中聲明和初始化F#中定義的歧視聯盟值?如何在C#中聲明並初始化F#中定義的歧視聯盟值?
F#代碼:
namespace Core
[<AutoOpen>]
module EventStore =
type Events =
| BuyRequested of RequestInfo
| SellRequested of RequestInfo
RequestInfo被定義爲以下:
namespace Core
[<AutoOpen>]
module Entities =
type RequestInfo = {
AccountId : string
Symbol : string
Quantity : int
}
C#客戶:
var myEvent = new Events.NewBuyRequested(requestInfo); // Doesn't compile
我試圖引用此link,這樣我可以參考下面的例子:
type Shape =
| Circle of float
| Rectangle of float * float
C#:
var circle = Shape.NewCircle(23.77);
var rectangle = Shape.NewRectangle(1.5, 2.2);
但是我沒有看到暴露我的DU情況下的值的任何方法(即BuyRequested,SellRequested)。
從「new Events.NewBuyRequested」中刪除新的。它現在有效。 –