【问题标题】:How to merge two classes into single unit?如何将两个类合并为一个单元?
【发布时间】:2014-06-13 13:37:40
【问题描述】:
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],0),Globals.GetInt( AccountCodeCustomArray[i],0), 
     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;

ReportDataInfo 看起来像

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

【问题讨论】:

  • List&lt;T&gt; 有一个 AddRange() 方法。你试过吗?
  • 没有@EladLachmi 的例子对我来说很好
  • msdn.microsoft.com/en-us/library/z883w3dc(v=vs.110).aspx - 关于List&lt;T&gt; 的AddRange 的MSDN 页面。这个想法是 AddRange 采用 IEnumerable&lt;T&gt; 并将其附加到列表的末尾。这就是你想要的,对吧?还是我误会了?

标签: c# asp.net .net linq list


【解决方案1】:

它只是使用 Automapper

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

【讨论】:

  • 你好 jayraj 你能给我举个例子吗?
猜你喜欢
  • 2013-07-09
  • 1970-01-01
  • 1970-01-01
  • 2018-01-01
  • 2019-07-25
  • 2012-08-16
  • 2011-11-24
  • 2014-06-25
  • 2014-06-16
相关资源
最近更新 更多