- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 FSharp 的 Microsoft Office PIA。当我尝试像这样从 Microsoft Word 获取 SynonymInfo 时:
#r "Office.dll"
#r "Microsoft.Office.Interop.Word.dll"
open Microsoft.Office.Interop.Word
let application = ApplicationClass()
let synonymInfo = application.SynonymInfo("bracket")
let meaningList = synonymInfo.MeaningList :?> string[]
我遇到了这个异常:
System.InvalidCastException: Unable to cast object of type 'System.String[*]' to type 'System.String[]'.
是 COM 对象的转换导致的吗?我怎样才能正确转换这个? * 是元组吗?如果是这样 string[,] 也不起作用...
谢谢
最佳答案
Office 互操作返回一个数组,其中索引不是从 0 而是(可能)从 1(好旧的 Visual Basic 时代!)这就是类型 中的
.*
的含义字符串[*]
您甚至可以从 F# 创建这样的数组:
let array = System.Array.CreateInstance(typeof<int>, [| 10 |], [| 1 |])
不幸的是,Int32[*]
是与 Int32[]
不同的类型,因此转换失败:
// System.InvalidCastException: Unable to cast
// object of type 'System.Int32[*]' to type 'System.Int32[]'.
array :?> int[]
您需要以另一种方式将 1 索引数组中的数据转换为其他结构。我示例中的 array
类型实现了非泛型 IEnumerable
,因此您应该能够编写如下内容:
array |> Seq.cast<int> |> Array.ofSeq
如果您的情况下值的类型是obj
,您需要先将其转换为接口(interface):
(thing :?> IEnumerable) |> Seq.cast<string> |> Array.ofSeq
您还可以使用类似这样的方式获取包含索引值对的数组:
[| for i in array.GetLowerBound(0) .. array.GetUpperBound(0) ->
i, array.GetValue(i) :?> int |]
关于f# - FSharp 和 Microsoft Office PIA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36447260/
我已尽力在 Google 中找到答案。但我认为这与我的情况不符。 请给我一个指南。非常感谢。 如果您是我,您可以卸载 + 安装 Visual Emprise。 这个原因让我想了很多次。 感谢所有在我遇
给定一个具有 FSharp 样式函数的接口(interface)。 type IUseless = abstract member Listify: string -> int -> stri
我正在尝试将 F# 用于 ASP.NET MVC 应用程序。我的 Controller 操作将 F# 列表发送到 View ,因此我写道: >" %> 当然,要使其正常工作,我必须将 Microsof
这两个文件似乎与 FSharp.Core.dll 一起位于 F# 的目录中。 如果忘记将它们与 FSharp.Core.dll 放在一起,这两个文件似乎一直是麻烦的根源。 它们似乎是二进制文件,所以我
我很困惑。 我正在升级一个旧项目,它到处都引用了 FSharp.Core 4.4,但 nuget 上 fsharp.core 的最新版本是 4.1.*.* 是否有文件解释版本号倒退的情况? 最佳答案
我在发布 Visual Studio C# Web 服务时遇到问题。构建良好,运行良好,但在发布时出现这个奇怪的错误: Copying file any\netstandard1.6\FSharp.C
此问题基于本类(class)第一周的函数式随机生成器:https://www.coursera.org/course/reactive 该类(class)基于 Scala,我正尝试在 FSharp 中
我需要为我的 F Sharp 记录修改和添加新属性。但随后它会为没有这个新字段的先前实例提供错误。我把它设置为 Nullable ,但仍然出现同样的错误,请帮我解决这个问题 最佳答案 我认为您的意思是
我刚刚真正进入 FSharp 并且我已经为此苦苦挣扎了很长一段时间,因为我不明白为什么我没有在比赛声明中得到预期的结果。 根据消息编号,我需要将数组(拆分)中的某些值与我想要返回的记录上的字段相匹配。
假设我正在使用如下列表: let items = [ Some(1); None; Some(8); ];; 只有Some的最短方法是什么?列表中的值? items |> List.filter Op
似乎必须覆盖 Equality 才能覆盖比较。 这是真的吗?我失踪有什么原因吗? 最佳答案 不。可以只进行自定义比较 [] [] type Node = | Data of string
由于 FSharp 中具有多个参数的函数会固有地变成只有一个参数的函数,Seq.filter 的签名应该不得不 Seq.filter predicate source ? 会有多不同 Seq.filt
是否等效/更好地工作 与 Event module在 Event type 或在 publish 上使用 Observable事件的属性 从功能上看,它似乎是等效的,我想区别在于“语义”: 我们是否在
我正在研究具有多个状态的 F# 代理,即使用“let rec/and”关键字组合(根据 Expert F# 3.0 的“消息处理和状态机”)来提供多个异步 block 。到目前为止我能找到的唯一例子是
我正在尝试使用 F# 生成随机三元组列表 -> 两个随机数及其总和: let foo minNum maxNum = let rnd = System.Random() let fir
我想以特定方式格式化元组,并且我尝试通过检查元组的类型(2 个元素、3 个元素等)来实现此目的。我在第三行收到错误消息: This runtime coercion of type test from
以下表达式是否会使用 fsharp 编译器生成任何代码? let xs = List.rev <| List.rev xs 最佳答案 不,事实并非如此。您可以查看 sharplab 上的输出 IL验证
这个问题已经有答案了: Ranges A to B where A > B in F# (5 个回答) 已关闭10 年前。 有没有一种方法可以按降序排列范围? 例如 [1..4] 评估为 > val
我想以特定方式格式化元组,并且我尝试通过检查元组的类型(2 个元素、3 个元素等)来实现此目的。我在第三行收到错误消息: This runtime coercion of type test from
以下表达式是否会使用 fsharp 编译器生成任何代码? let xs = List.rev <| List.rev xs 最佳答案 不,事实并非如此。您可以查看 sharplab 上的输出 IL验证
我是一名优秀的程序员,十分优秀!