将自定义类型从VB6转换为List<>在C#?

时间:2012-02-29 14:38:05

标签: c# vb6 casting

确定。

我有一个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

时间表> 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)转换或转换为List&lt;&gt;的任何提示和/或指示。将受到高度赞赏。

提前致谢。

2 个答案:

答案 0 :(得分:0)

您可能必须手动遍历列表并将数据复制到新的

List<your_new_similar_class>

至少如果你想要快速修复。

答案 1 :(得分:0)

也许这个?

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