[英]Copying a generic list to another, with different data types takes too long (C#)
I have a List<CallLog>
, where CallLog
has the following properties: 我有一个List<CallLog>
,其中CallLog
具有以下属性:
public string SomeProperty1 { get; set; }
public string SomeProperty2 { get; set; }
public string SomePropertyN { get; set; }
public DateTime Date { get; set; }
public DateTime CallEndTime { get; set; }
I need to fill a (devexpress) grid data source with this list. 我需要用此列表填充(devexpress)网格数据源。 The grid has the following columns: 网格具有以下列:
Date | 日期| SomeProperty1 | SomeProperty1 | SomeProperty2 | SomeProperty2 | ... | ... | SomePropertyN | SomePropertyN | CallStartTime | CallStartTime | CallEndTime 通话结束时间
In fact, I am using the Date
property in 2 columns, in the first column (Date), I use only the date
part and in the other column (CallStartTime), I use the time
part only. 实际上,我在两列中使用Date
属性,在第一列(日期)中,我仅使用date
部分,在另一列中(CallStartTime)中,我仅使用time
部分。
Unfortunately, gridxview
fails to perform proper grouping when I simply ask it to show different formats of my Date
property in 2 columns. 不幸的是,当我只是要求它在2列中显示Date
属性的不同格式时, gridxview
无法执行正确的分组。 So, I decided to create a customized class and copy the original list into a new list ( List<CustomizedCallLog>
) and pass the new list as the grid data source. 因此,我决定创建一个自定义类,并将原始列表复制到新列表( List<CustomizedCallLog>
)中,并将新列表作为网格数据源传递。 Below is how I am doing this. 以下是我的操作方式。 But it takes too long. 但这需要太长时间。 Is there any fast way to copy the list? 有什么快速的方法可以复制列表?
My customized call log class: 我的自定义呼叫日志类:
Public Class CustomizedCalLog
{
public DateTime Date { get; set; }
public string SomeProperty1 { get; set; }
public string SomeProperty2 { get; set; }
public string SomePropertyN { get; set; }
public string CallStartTime { get; set; }
public string CallEndTime { get; set; }
public CustomizedCallLog(CallLog log)
{
this.Date = log.Date;
this.SomeProperty1 = log.SomeProperty1 ;
this.SomeProperty2 = log.SomeProperty2 ;
this.SomePropertyN = log.SomePropertyN ;
this.CallStartTime = log.Date.ToString("H:mm");
this.CallEndTime = log.CallEndTime.ToString("H:mm");
}
}
Setting the grid: 设置网格:
private void SetGrid()
{
var logs = someBusiness.GetLogs();
List<CustomizedCallLog> dataSource = new List<CustomizedCallLog>();
foreach (var log in logs)
{
dataSource.Add(new CustomizedCallLog(log));
}
grid.ForceDataRowType(typeof(CustomizedCallLog));
grid.DataSource = dataSource;
grid.DataBind();
}
My issue is resolved using the comment by @Yuval Itzchakov. 我的问题已通过@Yuval Itzchakov的评论解决。
I could not add the new properties to my existing class since the existing class was auto-generated (with some .tt file). 由于现有类是自动生成的(带有一些.tt文件),因此无法将新属性添加到现有类中。
So, I left the code as it is, and improved the this.SomePropertyX = log.SomePropertyX
bit of code which was making a bottleneck. 因此,我按原样保留了代码,并对this.SomePropertyX = log.SomePropertyX
进行了改进,这成为了瓶颈。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.