2012-02-29 86 views
0

好的。將自定義類型從VB6轉換爲C#中的List <>?

我有一個VB6編譯的DLL,我已經導入到web服務(C#ASMX)。

在VB6我有這個以下幾種類型:

Public Type typeAccountInfo 
    singular  As String 
    code    As String 
    description  As String 
End Type 

Public Type timeSheetRowPost 
    lock   As Boolean 
    code   As String 
    from   As Long 
    to    As Long 
    fakt   As Boolean 
    ik    As String 
    ek    As String 
    ak    As String 
    accounts()  As typeAccountInfo 
End Type 

Public Type timeSheetDayPosts 
    date   As String 
    scheduleFrom As Long 
    scheduleTo  As Long 
    break   As Long 
    dagPost()  As timeSheetRowPost 
End Type 

Public Type timeSheet 
    period   As String 
    dayCount   As Long 
    days()  As timeSheetDayPosts 
End Type 

的TimeSheet> timeSheetDayPosts> timeSheetRowPosts> typeAccountInfo

我有一個VB6功能得到我需要的所有數據。

,當我在我的web ASMX實現這一點,我這樣做以下列方式:

public List<returnType> myFunction(input parameters){ 

    List<timeSheet> VB6Array = new List<timeSheet>(); 
    VB6Array = new List<timeSheet>((timeSheet[])VBWrapper.myVB6Func(input params)); 


    // at this point VB6Array holds all the data i need. And all i need (want) at this point is to be able to cast this VB6(system.array) to a List<> object that i can return as my returntype. 

// Pseudo : List<ReturnType> myNewReturnType = new List<ReturnType>((ReturnType[])VB6Array); 

// However all my tries has been without success....and what i get is You must implement a default accessor on System.Array because it inherits from ICollection. 

return myNewReturnType; 
} 

就怎麼投或轉換VB6的類型(System.Array的)的任何提示和/或指針名單<>將不勝感激。

在此先感謝。

回答

0

您可以通過列表必須手動循環,並將數據複製到一個新的

List<your_new_similar_class> 

至少,如果你想速戰速決。

+0

我有我的希望,但它給了我: 無法通過類型「system.collections.generic.list 」轉換爲「列表」一個內置的轉換 – doge 2012-02-29 14:47:10

+0

對不起近卻無雪茄Da_smokes。 btw對你的健康有害。 – Har 2012-03-01 14:53:25

+0

手動循環瀏覽列表並添加它們我的自己的類型工作正常,這只是一個問題。 – doge 2012-03-05 06:57:06

0

也許這樣?

VB6Array = ((List<API.timeSheet>)VBWrapper.myVB6Func(input params)) 
.Select(x => new timeSheet { period = x.period, ... }).ToList(); 
+0

對您有幫助嗎? – MarkH 2012-03-02 09:25:20

+0

它沒有解決每個人的問題,但它打開了一些想法。但問題解決了。 – doge 2012-03-05 06:46:36

相關問題