【发布时间】:2013-01-22 16:44:04
【问题描述】:
例如,如果我在 F# 中编写了一个模块
module Lib
type A =
member this.x1 x = ...
let helpa x = ...
let helpb x = ...
type B =
member this.y1 x = ...
let helpc x = ...
typeA with
member this.x2 x = ...
typeB with
member this.y2 x = ...
open Lib 在 F# 中运行良好,但是,如果我想在 C# 中使用它(我只对 Lib 中的类型和成员函数感兴趣),每次创建类型时我都必须 @ 987654327@。没有办法省略模块名称变得相当烦人。调用像Lib.A.C() 这样的静态方法就更麻烦了。
然后我尝试将module 替换为namespace,每次引入一些辅助函数时,我都必须创建一个具有新名称的新模块。有时我可以设法将所有辅助函数重新排列到 1 个模块中,但这会导致代码的可读性降低。
什么是更好的结构?
希望我有:Using * = Lib.* 用于 C#。
【问题讨论】:
-
您的 C# 类顶部是否有
using Lib指令? msdn.microsoft.com/en-US/library/sf0df423(v=vs.80).aspx -
@RobertHarvey 我不认为 C# 可以
using模块,或者你的意思是别名,如using A = Lib.A? -
你可以在这里找到其他有用的建议stackoverflow.com/questions/10110174/…
标签: f#