在C#中使用来自F#的非歧视联盟类型

pry*_*ain 1 f#

我在F#库中声明了一些我希望从C#代码中填充的数据类型.我遇到的问题是只有DU被"导出"为一个类,请考虑这个示例文件Test.fs:

module Test

type SimpleType = string

type SimpleList = string list

type SimpleDU =
     | A
     | B

type SimpleRecord = { Text : string }
Run Code Online (Sandbox Code Playgroud)

刚开始引用F#项目时我很困惑,我不允许在C#中使用SimpleTypeSimpleList类型.我查看了生成的带有ILDasm的F#库,并且只找到了C#代码中可以完全访问的SimpleDUSimpleRecord类型的代码.

有没有办法"导出"非DU类型,以便它们可以在C#中使用,或者我是否必须将每个非DU类型声明为显式记录?

Lee*_*Lee 5

的定义

type SimpleType = string
type SimpleList = string list
Run Code Online (Sandbox Code Playgroud)

是类型abbreiviations,在类型检查期间被删除,不创建新类型.这些在规范中描述:

8.3类型缩写

类型缩写为其他类型定义新名称.例如:

type PairOfInt = int * int
Run Code Online (Sandbox Code Playgroud)

类型缩写在编译期间被扩展和擦除,并且不会出现在F#声明的详细形式中,也不能在运行时引用或访问它们.