2

我在让主详细信息记录与泛型一起使用时遇到问题。我的代码如下

// Setup file engine with Master/Detail types
MasterDetailEngine<PurchaseOrderHeader, PurchaseOrderLine> engine = new MasterDetailEngine<PurchaseOrderHeader, PurchaseOrderLine>(CommonSelector.MasterIfBegins, "H");

// Init the Master/Detail
MasterDetails<PurchaseOrderHeader, PurchaseOrderLine> poRecs = new MasterDetails<PurchaseOrderHeader, PurchaseOrderLine>();

// Setup list for detail lines & populate with test data
List<PurchaseOrderLine> poLines = new List<PurchaseOrderLine>();

for (int i = 1; i <= 5; i++)
{
    poLines.Add(new PurchaseOrderLine() { LineMarker = "L", LineNumber = i, ItemCode = "TestCode", Price = 12.34M, Quantity = i * 2, UOM = "EA" });
}

// Attach records to Master/Detail
poRecs.Master = new PurchaseOrderHeader() { LineMarker = "H", PayloadID = "3223232@ariba.acme.com", CustomerPO = "DO1234", ShipToAddressCode = "ShipToAddressCode", BillToAddressCode = "BillToAddressCode" };
poRecs.Details = poLines.ToArray();

// Write file
engine.WriteFile("SampleFile.txt", poRecs);

我收到以下编译错误:

CS1502:最好的重载方法匹配 FileHelpers.MasterDetail.MasterDetailEngine<ImportExport.PurchaseOrderHeader,ImportExport.PurchaseOrderLine>.WriteFile(string,System.Collections.Generic.IEnumerable<FileHelpers.MasterDetail.MasterDetails<ImportExport.PurchaseOrderHeader,ImportExport.PurchaseOrderLine>>)

有一些无效的论点。

我尝试过投射poRecsIEnumerable但仍然无法正常工作。

任何建议将不胜感激!

4

1 回答 1

1

看起来对WriteFile期望的调用是 a IEnumerable<MasterDetails<PurchaseOrderHeader, PurchaseOrderLine>>,而您只是传入 a MasterDetails<PurchaseOrderHeader, PurchaseOrderLine>

当然,您不能将 a转换MasterDetails为 an,IEnumerable因为它们不可转换。您需要做的是poRecsIEnumerable. 尝试以下操作:

engine.WriteFile("SampleFile.txt", new[] { poRecs });
于 2013-01-17T03:06:35.027 回答