2014-03-03 93 views
1

使用ILSPY我發現,有BV method可用內bvlsFortran.dll 然而ILSPY說,這是CALCBV!BV enter image description here ,看看是否是正確的,我添加在Visual Studio中的參考,然後在主: enter image description here調用方法

![enter image description here][3] 

    Assembly SampleAssembly; 
    SampleAssembly = Assembly.LoadFrom("bvlsFortran.dll"); 
    // Obtain a reference to a method known to exist in assembly. 
    MethodInfo Method = SampleAssembly.GetTypes()[0].GetMethod("CALCBV!BV"); 
    // Obtain a reference to the parameters collection of the MethodInfo instance. 
    ParameterInfo[] Params = Method.GetParameters(); 
    // Display information about method parameters. 
    // Param = sParam1 
    // Type = System.String 
    // Position = 0 
    // Optional=False 
    foreach (ParameterInfo Param in Params) 
    { 
     Console.WriteLine("Param=" + Param.Name.ToString()); 
     Console.WriteLine(" Type=" + Param.ParameterType.ToString()); 
     Console.WriteLine(" Position=" + Param.Position.ToString()); 
     Console.WriteLine(" Optional=" + Param.IsOptional.ToString()); 
    } 

它是正確的,它顯示有關它的信息。

enter image description here 我該如何調用該方法? 我不能寫CALCBV!BV因爲編譯器抱怨... 如果我寫BVbvlsFortran方法它不會找到它。

回答

1

如果它是基於.net的dll,並且您有任何方法在應用程序中引用它,爲什麼要使用反射?嘗試直接調用方法,而不是通過bvlsFortran.BV

1

您可以在Methodinfo上調用Invoke,其中包含要傳遞給該函數的參數數組。

名稱CALCBV!BV可能是混淆的結果,該dll的發佈者不希望您直接調用它。

Method.Invoke(args);