繁体   English   中英

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

[英]Casting a custom type from VB6 to a List<> in C#?

好。

我有一个已导入到Web服务(C#ASMX)的VB6编译DLL。

在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函数,可以获取我需要的所有数据。

当我在webservice 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 <>的任何技巧和/或指针。

提前致谢。

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

List<your_new_similar_class>

至少如果您想快速修复。

也许这个吗?

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM