访问命名空间含有.base从F#的名字名字、空间、base

2023-09-04 10:29:37 作者:幼儿园扛把子

正如标题所说,我试图使用包含在其名称中的基地命名空间中声明一个类。 想想这样的情况如下:

As the title says, I'm trying to use a class declared in a namespace which contains "base" in its name. Think of a situation like the following:

open Foo.base.Bar

在C#我只是用@基地之前,但F#似乎忽略了这一点,并认为@是用作连接列表中缀运算符。 由于空间属于第三方库,我不能修改,是有办法,我仍然可以从F#访问它?

In C# I'd just use @ before base but F# seems to ignore that and to think that @ is the infix operator used for list concatenation. Since the namespace belongs to a third-party library which I cannot modify, is there a way I can still access it from F#?

推荐答案

在F#中,你可以通过封闭2双``符号之间的特殊名称实现类似的事情。下面应该做的伎俩:

In F#, you can achieve similar thing by enclosing the special name between two pairs of `` symbols. The following should do the trick:

open Foo.``base``.Bar

这是更灵活的比在C#中位 - 该名称可以包含几乎所有的东西,这样你就可以例如定义成员的命名空间:

This is a bit more flexible than in C# - the name can contain almost anything, so you can for example define members with space in the name:

let ``some name!`` = 42