我在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#中使用SimpleType和SimpleList类型.我查看了生成的带有ILDasm的F#库,并且只找到了C#代码中可以完全访问的SimpleDU和SimpleRecord类型的代码.
有没有办法"导出"非DU类型,以便它们可以在C#中使用,或者我是否必须将每个非DU类型声明为显式记录?
的定义
type SimpleType = string
type SimpleList = string list
Run Code Online (Sandbox Code Playgroud)
是类型abbreiviations,在类型检查期间被删除,不创建新类型.这些在规范中描述:
8.3类型缩写
类型缩写为其他类型定义新名称.例如:
Run Code Online (Sandbox Code Playgroud)type PairOfInt = int * int类型缩写在编译期间被扩展和擦除,并且不会出现在F#声明的详细形式中,也不能在运行时引用或访问它们.