【发布时间】:2017-02-22 13:00:27
【问题描述】:
我正在尝试将 F# 项目添加到我的 C# 解决方案中。我创建了一个 F# 项目并编写了一些 F# 代码,现在我正在尝试从我的 C# 项目中使用它。 我成功地引用了 F# 项目并且可以访问它的类型,但是有歧视联合的问题。例如,我在 F# 中定义了以下类型:
namespace Sample
type NotificationReceiverUser = NotificationReceiverUser of string
type NotificationReceiverGroup = NotificationReceiverGroup of string
type NotificationReceiver = NotificationReceiverUser | NotificatonReceiverGroup
我可以直接创建 NotificationReceiverUser 对象如下:
var receiver = NotificationReceiverUser.NewNotificationReceiverUser("abc");
,但我需要 NotificationReceiver 对象,而且我没有得到 NotificationReceiver.NewNotificationReceiverUser 或 NotificationReceiver.NewNotificationReceiverGroup 静态方法。查看其他一些 SO 问题,这些方法似乎默认情况下应该可用。非常感谢任何关于他们为什么对我失踪的指示。
【问题讨论】:
标签: c#-to-f#