在 F# 中获取引用的程序集
我正在尝试通过迭代加载引用的程序集。
我加载程序集,并通过 getRefs 获取引用的程序集。 getRefs 没有任何输入参数,所以应该是 val getRefs: Assembly->AssemblyName[],但认为是 unit->AssemblyName[], 有什么想法吗?
let getreffiles (name:string) =
let loadAssembly (name:string)=
Assembly.Load(name)
let getRefs (assembly:Assembly)=
assembly.GetReferencedAssemblies
//Get the referenced assembly list and print the full name to console
name
|>loadAssembly
|>getRefs
|>List.iter (fun s ->
printfn "Referenced Assembly name %s types" s.FullName);;
Type mismatch. Expecting a (unit -> AssemblyName []) -> 'a but given a 'b list -> unit
The type 'unit -> AssemblyName []' does not match the type ''a list'
C:\Users\Ebru\Documents\Visual Studio 2010\Projects\Find\GetAssembly.fs
I am trying to load the referenced Assemblies through an iteration.
I load the assembly, and get the referenced assemblies by getRefs. getRefs does not have any input parameters so it should be val getRefs: Assembly->AssemblyName[], but thinks it is unit->AssemblyName[],
any ideas?
let getreffiles (name:string) =
let loadAssembly (name:string)=
Assembly.Load(name)
let getRefs (assembly:Assembly)=
assembly.GetReferencedAssemblies
//Get the referenced assembly list and print the full name to console
name
|>loadAssembly
|>getRefs
|>List.iter (fun s ->
printfn "Referenced Assembly name %s types" s.FullName);;
Type mismatch. Expecting a (unit -> AssemblyName []) -> 'a but given a 'b list -> unit
The type 'unit -> AssemblyName []' does not match the type ''a list'
C:\Users\Ebru\Documents\Visual Studio 2010\Projects\Find\GetAssembly.fs
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须通过在末尾添加 () 来执行 GetReferencedAssemblies 方法。如果不添加“()”,您只是返回对该函数的引用,而不是返回该函数的结果。另外,将 List.iter 更改为 Array.iter。 GetReferencedAssemblies 返回数组,而不是列表。
You have to execute the method GetReferencedAssemblies, by adding a () at the end. Without adding that "()", you're simply returning a reference to the function instead of returning the results of the function. Also, change List.iter to Array.iter. GetReferencedAssemblies returns and array, not a list.
如果函数没有输入,则其输入的类型为“unit”。这与 C 中的 void 类似,只不过函数参数是显式的。
If a function has no inputs its input is of type 'unit.' This is similar to void in C, except the function parameter is explicit.