如何在程序集中查看类型提供程序
How to view type providers in the assembly
我正在查看对象资源管理器并试图找出 where/how 类型提供程序已定义 - 我正在查看 FSharp.Data.dll。它显示 CsvFile 和 CsvRow.. 但我找不到 CsvProvider。那是在哪里定义的?我是否应该仅依靠文档来找出给定程序集中的提供程序类型?
FSharp.Data.dll
是 FSharp.Data
的 run-time 组成部分。 Type-providers 在 compile-time 期间为您生成类型,之后就不需要了。该 dll 称为:FSharp.Data.DesignTime.dll
.
您可以反编译那个 dll,但我认为只看源代码更容易:https://github.com/fsharp/FSharp.Data/blob/master/src/Json/JsonProvider.fs
类型提供程序的作用是注入代码和类型,使导航 JSON 对您来说很方便。使用像 dnSpy
这样的工具可以找出实际发生的事情
所以示例程序
type Simple = JsonProvider<""" { "name":"John", "age":94 } """>
let f (s: string) =
let s = Simple.Parse s
s.Name
使用 dnSpy
将其反编译为 C# 后如下所示:
public static string f(string s)
{
IJsonDocument s2 = (IJsonDocument)JsonDocument.Create(new StringReader(s));
JsonValueOptionAndPath jsonValueOptionAndPath = JsonRuntime.TryGetPropertyUnpackedWithPath(s2, "name");
return JsonRuntime.GetNonOptionalValue<string>(jsonValueOptionAndPath.Path, JsonRuntime.ConvertString("", jsonValueOptionAndPath.JsonOpt), jsonValueOptionAndPath.JsonOpt);
}
所以字符串被解析成IJsonDocument
然后s.Name
变成
JsonValueOptionAndPath jsonValueOptionAndPath = JsonRuntime.TryGetPropertyUnpackedWithPath(s2, "name");
return JsonRuntime.GetNonOptionalValue<string>(jsonValueOptionAndPath.Path, JsonRuntime.ConvertString("", jsonValueOptionAndPath.JsonOpt), jsonValueOptionAndPath.JsonOpt);
关于代码不需要 FSharp.Data.DesignTime.dll
因此它不包含在构建中。
我正在查看对象资源管理器并试图找出 where/how 类型提供程序已定义 - 我正在查看 FSharp.Data.dll。它显示 CsvFile 和 CsvRow.. 但我找不到 CsvProvider。那是在哪里定义的?我是否应该仅依靠文档来找出给定程序集中的提供程序类型?
FSharp.Data.dll
是 FSharp.Data
的 run-time 组成部分。 Type-providers 在 compile-time 期间为您生成类型,之后就不需要了。该 dll 称为:FSharp.Data.DesignTime.dll
.
您可以反编译那个 dll,但我认为只看源代码更容易:https://github.com/fsharp/FSharp.Data/blob/master/src/Json/JsonProvider.fs
类型提供程序的作用是注入代码和类型,使导航 JSON 对您来说很方便。使用像 dnSpy
这样的工具可以找出实际发生的事情
所以示例程序
type Simple = JsonProvider<""" { "name":"John", "age":94 } """>
let f (s: string) =
let s = Simple.Parse s
s.Name
使用 dnSpy
将其反编译为 C# 后如下所示:
public static string f(string s)
{
IJsonDocument s2 = (IJsonDocument)JsonDocument.Create(new StringReader(s));
JsonValueOptionAndPath jsonValueOptionAndPath = JsonRuntime.TryGetPropertyUnpackedWithPath(s2, "name");
return JsonRuntime.GetNonOptionalValue<string>(jsonValueOptionAndPath.Path, JsonRuntime.ConvertString("", jsonValueOptionAndPath.JsonOpt), jsonValueOptionAndPath.JsonOpt);
}
所以字符串被解析成IJsonDocument
然后s.Name
变成
JsonValueOptionAndPath jsonValueOptionAndPath = JsonRuntime.TryGetPropertyUnpackedWithPath(s2, "name");
return JsonRuntime.GetNonOptionalValue<string>(jsonValueOptionAndPath.Path, JsonRuntime.ConvertString("", jsonValueOptionAndPath.JsonOpt), jsonValueOptionAndPath.JsonOpt);
关于代码不需要 FSharp.Data.DesignTime.dll
因此它不包含在构建中。