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

时间:2010-02-24 16:14:54

标签: assembly f# lambda

我试图通过迭代加载引用的Assemblies 我加载程序集,并通过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 

2 个答案:

答案 0 :(得分:7)

您必须通过在末尾添加()来执行方法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);;  

答案 1 :(得分:0)

如果函数没有输入,则其输入的类型为“unit”。这类似于C中的void,除了函数参数是显式的。