我试图让我的头脑类型提供商在F#和他们可以用来。我有以下问题:
Azure Blob存储中存储了一系列JSON对象,如下所示:
container/YYYY/MM/DD/file.json我可以使用类型提供程序轻松地导航到给定日期的特定文件。例如,我可以在5月5日作为字符串访问JSON对象
type Azure = AzureTypeProvider<"ConnectionString">
let containers = Azure.Containers.``container``.``2017/``.``05/``.``05/``.``file.json``.Read()如何获取用户输入日期字符串,例如"2017-05-05“,并以类型安全的方式获取相应的JSON对象?我应该使用类型提供程序吗?
发布于 2017-05-19 11:48:41
您正遇到一个与许多TPs的性质有关的常见“问题”,特别是那些针对实际数据提供模式的TPs--因为它将数据和类型之间的界限混合在一起,您需要知道什么时候您在与静态类型很好地工作的模式(即在编译时知道您正在使用的blob容器的模式),或者以一种本质上是动态的方式工作。
你有几个选择。
AsCloudBlob()或AsCloudContainer()方法,因此您可以对已知的位使用TP,例如容器名称、可能是顶级文件夹等,然后返回到本地SDK对弱类型的位。- You can use indexers to get an unsafe handle to a blob e.g. `let blob = Azure.Containers.container.["2017/05/05/file.json"]`. There's no guarantee that the blob exists, so you need to check that yourself etc.
- You can use the `TryGetBlockBlob()` method, which returns a `blob option async` - behind the scenes, it will do a check if the blob exists or not, and then return either None, or Some blob.
您可以看到所有这些替代方案的更多示例,这里。
https://stackoverflow.com/questions/44068490
复制相似问题