[英]using (Matlab) dll name at top of classes C#
我在Visual Studio 2017(Framework 4.5.2)中創建了一個C#程序,該程序調用了我創建的2個不同的Matlab dll(makesquareproject.dll和Calibrationsgproject.dll)。 這兩個dll都是使用Matlab庫編譯器(.NET程序集)制作的。 我在項目的引用中添加了dll,並且在整個程序中使用以下代碼對其進行了調用:
double[] points = new double[] { 4, 2, 3 }; // example
MWNumericArray mwpoints= new MWNumericArray(points);
MWArray[] result = MatlabHelper.Ml.MakeSquare(1, mwpoints); // MakeSquare is a function of the MakeSquareClass --> makesquareproject-dll
MWArray[] result2 = MatlabHelper.Lib.CalibrationSG(2, mwpoints); // CalibrationSG is a function of the CalibrationSGClass--> calibrationsgproject-dll
MatlabHelper類如下所示:
using makesquareproject; // dll that contains MakeSquare function
namespace myProject
{
class MatlabHelper
{
private static CalibrationSGClass _lib;
private static MakeSquareClass _ms
public static CalibrationSGClass Lib
{
get
{
if (_lib == null)
_lib = new CalibrationSGClass (); // CalibrationSGClass is the class name that is chosen when the calibrationsgproject-dll is created using the Library Compiler in Matlab
return _lib;
}
}
public static MakeSquareClass Ms
{
get
{
if (_ms == null)
_ms = new MakeSquareClass (); // MakeSquareClass is the class name that is chosen when the makesquareproject-dll is created using the Library Compiler in Matlab
return _ms;
}
}
}
}
我注意到對於makesquareproject-dll,我必須using makesquareproject;
進行添加using makesquareproject;
在MatlabHelper
的頂部,而在使用MatlabHelper
的類的頂部,沒有任何MatlabHelper
。 與此相反,我不必using calibrationsgproject;
到MatlabHelper
的頂部,但我必須將其添加到所有使用MatlabHelper
類中。 為什么會這樣,我做錯什么了嗎?
在這里, using
只是使用類型而不用名稱空間作為前綴的快捷方式(您可以編寫makesquareproject.MakeSquareClass
並刪除using)。
不要混合using
(這只是編寫代碼的一種幫助)和對dll的引用,而從該dll中查找任何對象都是必需的(使用MatlabHelper的所有項目都必須引用makesquareproject -如果進入bin文件夾,則會找到dll並在運行時加載)
因此,MakeSquareClass不會用任何其他函數編寫->您不需要在其他文件中using makesquareproject
(這並不意味着將不使用該類型,該類型將正確解析為makesquareproject.MakeSquareClass)。
我不確定您描述的行為-您確定在CalibrationSGClass
中定義了calibrationsgproject
嗎? 檢查它的名稱空間(例如,如果您在Visual Studio上,則可以通過引用進行引用,或者通過GetType()
檢索名稱空間),我假設它也在makesquareproject中定義。
從您發布的內容來看,我會說MakeSquareClass和CalibrationSGClass是在makesquareproject中定義的,而MWArray或其他是在Calibrationsgproject中定義的。 可以肯定的是,刪除使用並檢查異常,您將知道哪些類型未知
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.