本文整理汇总了C#中Common.List.Except方法的典型用法代码示例。如果您正苦于以下问题:C# List.Except方法的具体用法?C# List.Except怎么用?C# List.Except使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Common.List
的用法示例。
在下文中一共展示了List.Except方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MergeItems
private List<CalendarItem> MergeItems(List<CalendarItem> newItems, List<CalendarItem> fromRepo)
{
var result = new List<CalendarItem>();
var newModels = newItems.Except(fromRepo, new CalendarItemEqualityComparer()).ToList();
var updatet = fromRepo.Except(newModels,new CalendarItemEqualityComparer()).ToList();
updatet.ForEach(x =>
{
var model = newItems.FirstOrDefault(y => y.Id == x.Id);
if (model != null)
{
model.SyncStatus.CalenadCalendarItemStatus = IsModified(model, x)
? CalendarItemStatus.Updated
: CalendarItemStatus.Unmodified;
result.Add(model);
}
});
var deleted = fromRepo.Where(x => x.Start.Date >= DateTime.Now.Date).Except(newItems).Except(updatet);
newModels.ForEach(x => x.SyncStatus.CalenadCalendarItemStatus = CalendarItemStatus.New);
deleted.ForEach(x =>
{
x.SyncStatus.CalenadCalendarItemStatus = CalendarItemStatus.Deleted;
result.Add(x);
});
result.AddRange(newModels);
return result.OrderBy(x => x.Start).ToList();
}
示例2: Update
/// <summary>
/// You are allowed a route with no departure times, so this method doesn't check that departure times exist already.
/// </summary>
/// <param name="route_id"></param>
/// <param name="event_id"></param>
/// <param name="departureTimes"></param>
public void Update(int route_id, int event_id, List<WeeklyTime> departureTimes)
{
// check values
if (route_id == 0)
throw new ArgumentException("Route_id cannot be zero", "route_id");
if (event_id == 0)
throw new ArgumentException("Event_id cannot be zero", "event_id");
if (departureTimes == null)
throw new ArgumentException("departureTimes cannot be null", "departureTimes");
var currentList = Load(route_id);
var difference = departureTimes.Except(currentList, new WeeklyTime.Comparer()).ToList<WeeklyTime>();
if (difference.Count() == 0)
return; // you are allowed to call update even if it doesn't make a difference.
// get times to add and remove
var toDelete = difference.Intersect(currentList, new WeeklyTime.Comparer()).ToList<WeeklyTime>();
var toAdd = difference.Intersect(departureTimes, new WeeklyTime.Comparer()).ToList<WeeklyTime>();
lock (Database.Instance)
{
// save all new entries
foreach (WeeklyTime time in toAdd)
{
var sql = SQLQueryBuilder.CreateNewRecord(TABLE_NAME, ID_COL_NAME, new[] { EVENT_ID, "route_id", "weekly_time" }, new string[] { event_id.ToString(), route_id.ToString(), time.Value.Ticks.ToString() });
Database.Instance.InsertQuery(sql);
}
// delete all non existing entries
foreach (WeeklyTime time in toDelete)
{
// get the id
int departure_time_id = GetId(route_id, time);
// set entry to inactive
var sql = String.Format("UPDATE `{0}` SET active=0 WHERE {1}={2}", TABLE_NAME, ID_COL_NAME, departure_time_id);
Database.Instance.InsertQuery(sql);
// insert new 'deleted' row
sql = SQLQueryBuilder.InsertFields(TABLE_NAME,
new string[] { EVENT_ID, ID_COL_NAME, "active", "route_id", "weekly_time" },
new string[] { event_id.ToString(), departure_time_id.ToString(), "-1", route_id.ToString(), "" });
Database.Instance.InsertQuery(sql);
}
}
}