当前位置: 首页>>代码示例>>C#>>正文


C# List.Except方法代码示例

本文整理汇总了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();
 }
开发者ID:Ahrimaan,项目名称:ChaosCalendarSync,代码行数:26,代码来源:CalendarMerger.cs

示例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);
                }

            }
        }
开发者ID:patrick478,项目名称:SWEN301-KPSmart,代码行数:57,代码来源:DepartureTimeDataHelper.cs


注:本文中的Common.List.Except方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。