在 F# 中获取引用的程序集

发布于 2024-08-22 09:13:41 字数 893 浏览 8 评论 0原文

我正在尝试通过迭代加载引用的程序集。
我加载程序集,并通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

〗斷ホ乔殘χμё〖 2024-08-29 09:13:41

您必须通过在末尾添加 () 来执行 GetReferencedAssemblies 方法。如果不添加“()”,您只是返回对该函数的引用,而不是返回该函数的结果。另外,将 List.iter 更改为 Array.iter。 GetReferencedAssemblies 返回数组,而不是列表。

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   
     |> Array.iter (fun s -> 
           printfn "Referenced Assembly name %s  types" s.FullName);;  

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.

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   
     |> Array.iter (fun s -> 
           printfn "Referenced Assembly name %s  types" s.FullName);;  
巴黎夜雨 2024-08-29 09:13:41

如果函数没有输入,则其输入的类型为“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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文