[英]Two types defined in an F# module but only one visible in C#
I have an F# library where I defined a module. 我有一个F#库,我在其中定义了一个模块。 Inside the module there are 2 types defined. 模块内部定义了两种类型。 I'm accessing the library from C# project (currently it's only a test project though that probably doesn't matter). 我正在从C#项目访问该库(目前它只是一个测试项目,尽管这可能并不重要)。
I can access one of the types from C# but the other one is not available. 我可以从C#访问其中一种类型,但另一种类型不可用。
Below my F# code: 在我的F#代码下面:
module Stock
open FSharp.Data
open InstrumentQueryBuilder
type Stock = CsvProvider<"..\prototype_historical_data.csv">
type StockData(symbol) =
member this.Symbol = symbol
member private this.QueryBuilder = new InstrumentQueryBuilder(this.Symbol)
member this.LoadData() =
this.QueryBuilder.HistoricalData() |> Stock.Load
// more member definitions here...
From C# I can see StockData
but not Stock
. 从C#我可以看到StockData
而不是Stock
。 Stock
is CsvProvider
from FSharp.Data. Stock
是CsvProvider
从FSharp.Data。 In my C# code I'm referencing both FSharp.Data and FSharp.Core. 在我的C#代码中,我引用了FSharp.Data和FSharp.Core。
Using StockData
in C# is as simple as this: 在C#中使用StockData
就像这样简单:
var stockData = new Stock.StockData("SPY");
But if I do the same for Stock
it shows a compile time error. 但如果我为Stock
做同样的事情,它会显示编译时错误。 Any suggestion how to access the Stock
type or an explanation why that's not possible? 任何建议如何访问Stock
类型或解释为什么不可能?
In F#, type
has lot of meaning to it even though they all look very similar. 在F#中, type
对它有很多意义,即使它们看起来非常相似。
In you case, 在你的情况下,
Stock - Type abbreviation (alias). 股票 - 类型缩写(别名)。 Not a first class object. 不是第一类对象。 Thats why it is not visible to c#. 这就是为什么c#不可见。
StockData - It is class. StockData - 是班级。 Has function-style parameter list after name for use as constructor. 在名称后面有函数式参数列表用作构造函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.