gpt4 book ai didi

c# - 具有泛型的 FileHelpers 主/详细记录

转载 作者:太空宇宙 更新时间:2023-11-03 13:48:43 25 4
gpt4 key购买 nike

我在获取主要细节记录以使用泛型时遇到问题。我的代码如下

// 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: The best overloaded method match for FileHelpers.MasterDetail.MasterDetailEngine<ImportExport.PurchaseOrderHeader,ImportExport.PurchaseOrderLine>.WriteFile(string,System.Collections.Generic.IEnumerable<FileHelpers.MasterDetail.MasterDetails<ImportExport.PurchaseOrderHeader,ImportExport.PurchaseOrderLine>>)

has some invalid arguments.

我试过转换 poRecsIEnumerable但这仍然无法正常工作。

如有任何建议,我们将不胜感激!

最佳答案

看起来像是对 WriteFile 的调用期望一个 IEnumerable<MasterDetails<PurchaseOrderHeader, PurchaseOrderLine>> ,而你只是传递一个 MasterDetails<PurchaseOrderHeader, PurchaseOrderLine> .

当然你不能投MasterDetailsIEnumerable因为那些是不可兑换的。你需要做的是包装 poRecsIEnumerable .尝试以下操作:

engine.WriteFile("SampleFile.txt", new[] { poRecs });

关于c# - 具有泛型的 FileHelpers 主/详细记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14371277/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com