微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – 如何将两个类合并为一个单元?

List<ReportDataInfo> Lrdi = new List<ReportDataInfo>();
ReportDataInfo rdi = new ReportDataInfo();
ReportDataInfo RdiMerge=new ReportDataInfo();
string[] AccountTypeCodeCustomArray = 
AccountCodeTypeCustom.Split(",".tochararray());
string[] SubTypeCodeCustomArray = 
SubAccountTypeCodeCustom.Split(",".tochararray());
string[] AccountCodeCustomArray = AccountCodeCustom.Split(",".tochararray());
for (int i = 0; i < AccountCodeTypeCustom.Length; i++)
{
    rdi = ExportDataToCSV.GetLedgerReportData(Globals.GetInt( 
     AccountTypeCodeCustomArray[i],0),Globals.GetInt( 
     SubTypeCodeCustomArray[i],Globals.GetInt( AccountCodeCustomArray[i],this.CurrentSessionInfo.Company.CompanyCode,this.CurrentSessionInfo.FinancialYear.StartDate,this.CurrentSessionInfo.FinancialYear.EndDate);
   // Lrdi.Add(rdi);
    RdiMerge.Rows.Concat(rdi.Rows);                        
    //RdiMerge.Reportheading = rdi.Reportheading;
    //RdiMerge.Rows = rdi.Rows;
}

CurrentSessionInfo.ReportData = RdiMerge;

这是我以前尝试过的事情

现在我的问题是
我希望从ExportDataToCSV.GetLedgerReportData()返回合并返回的ReportDataInfo;

无论从ExportDataToCSV.GetLedgerReportData()返回什么值,我都被困在这里;
我想合并到单个ReportDataInfo然后传递给CurrentSessionInfo.ReportData = RdiMerge;

ReportDataInfolooks之类的

[Serializable]
public class ReportDataInfo
{
    public string Reportheading { get; set; }
    public List<ReportColumnInfo> Rows { get; set; }
}

解决方法

它只是使用Automapper

AutoMapper是一个对象到对象的映射器,它允许您解决将一种类型的一个对象中的相同属性映射到另一种类型的另一个对象的问题.例如,可以使用AutoMapper自动将重型实体Customer对象映射到CustomerDTO

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐