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


C# List.Reverse方法代码示例

本文整理汇总了C#中XCore.List.Reverse方法的典型用法代码示例。如果您正苦于以下问题:C# List.Reverse方法的具体用法?C# List.Reverse怎么用?C# List.Reverse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在XCore.List的用法示例。


在下文中一共展示了List.Reverse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReplaceListItem

		/// <summary>
		/// Replace SortObjects corresponding to hvoToReplace with new SortObjects for newObj.
		/// </summary>
		/// <param name="newObj"></param>
		/// <param name="hvoToReplace"></param>
		/// <param name="fAssumeSame">if true, we'll try to replace sort objects for hvoToReplace with newObj at the same indices.
		/// if false, we'll rely upon sorter to merge the new item into the right index, or else add to the end.
		/// Enhance: Is there some way we can compare the sort/filter results for newObj and hvoToReplace that is hvo indepedendent?</param>
		/// <returns>resulting list of newSortItems added to SortedObjects</returns>
		protected ArrayList ReplaceListItem(ICmObject newObj, int hvoToReplace, bool fAssumeSame)
		{
			ArrayList newSortItems = new ArrayList();
			// Note: don't check NeedToReloadVirtualProperty here, so we can update the list, even if we need to
			// reload it at a later time. This allows joining/breaking wordforms in the Concordance tools, without
			// necessarily having to reload the entire list. Typically replacements will be with real ids, and those
			// should be stable to add in the new view.
			//if (NeedToReloadVirtualProperty)
			//    return newSortItems;	// we don't need to update the list, if we're planning to reload the whole thing.
			List<int> indicesOfSortItemsToRemove = new List<int>(IndicesOfSortItems(new List<int>(new int[] { hvoToReplace })));
			ArrayList remainingInsertItems = new ArrayList();
			int hvoNewObject = 0;
			if (newObj != null)
			{
				hvoNewObject = newObj.Hvo;
				// we don't want to add new sort items, if we've already added them, but we do want to allow
				// a replacement.
				if (hvoToReplace == hvoNewObject || IndexOfFirstSortItem(new List<int>(new int[] { hvoNewObject })) < 0)
					MakeItemsFor(newSortItems, newObj);
				remainingInsertItems = (ArrayList)newSortItems.Clone();
				if (fAssumeSame)
				{
					//assume we're converting a dummy item to a real one.
					//In that case, the real item should have same basic content as the dummy item we are replacing,
					//so we can replace the item at the same sortItem indices.
					foreach (object itemToInsert in newSortItems)
					{
						if (indicesOfSortItemsToRemove.Count > 0)
						{
							int iToReplace = indicesOfSortItemsToRemove[0];
							SortedObjects.RemoveAt(iToReplace);
							SortedObjects.Insert(iToReplace, itemToInsert);
							indicesOfSortItemsToRemove.RemoveAt(0);
							remainingInsertItems.RemoveAt(0);
						}
						else
						{
							break;
						}
					}
				}
			}
			// Although, ideally, during a dummy conversion there should be a one-to-one correspondence between
			// the sort items found for the dummy object, and the sort items generated for its real object,
			// it's possible that at the time we added the dummy item to the record sort list, it didn't
			// have the same properties matching a filter or sorter as the real item. Try to do the best we
			// can by removing remaining sort items for the dummy object and then adding any additional sort items
			// for the real object.

			// remove the remaining items.
			indicesOfSortItemsToRemove.Sort();
			indicesOfSortItemsToRemove.Reverse();
			foreach (int iToRemove in indicesOfSortItemsToRemove)
			{
				SortedObjects.RemoveAt(iToRemove);
			}
			// add the remaining items.
			if (m_sorter != null)
			{
				m_sorter.MergeInto(SortedObjects, remainingInsertItems);
			}
			else
			{
				// Add at the end.
				SortedObjects.AddRange(remainingInsertItems);
			}

			// update our current selected hvo, if necessary
			if (m_hvoCurrent == hvoToReplace)
				m_hvoCurrent = hvoNewObject;
			return newSortItems;
		}
开发者ID:sillsdev,项目名称:WorldPad,代码行数:81,代码来源:RecordList.cs

示例2: RemoveUnwantedSortItems

		/// <summary>
		/// This will remove the given hvosToRemove (if they exist in our sort items) and any items that refer to invalid objects.
		/// Reload the view if there were any changes, and adjust the CurrentIndex
		/// </summary>
		protected internal void RemoveUnwantedSortItems(List<int> hvosToRemove)
		{
			if (m_sortedObjects == null)
				return;	// nothing to remove.
			bool fUpdatingListOrig = m_fUpdatingList;
			m_fUpdatingList = true;
			try
			{
				int currentIndex = CurrentIndex;
				int cOrigSortObjects = m_sortedObjects.Count;
				// Note: We start with a Set, since it can't have duplicates.
				// First remove the given hvos from our sort items.
				Set<int> unwantedIndices = new Set<int>(IndicesOfSortItems(hvosToRemove));
				// then remove any remaining items that point to invalid objects.
				unwantedIndices.AddRange(IndicesOfInvalidSortItems());
				// Put the now unique indices into a list,
				// so we can make sure they are processed in reverse order.
				List<int> sortedIndices = new List<int>(unwantedIndices.ToArray());
				sortedIndices.Sort();
				sortedIndices.Reverse();
				foreach (int indexOfSortItem in sortedIndices)
				{
					if (indexOfSortItem >= 0)
					{
						m_sortedObjects.RemoveAt(indexOfSortItem);
						if (indexOfSortItem < currentIndex || SortedObjects.Count <= currentIndex)
							currentIndex--;
					}
				}
				if (m_sortedObjects.Count == 0)
					currentIndex = -1;
				else if (currentIndex >= m_sortedObjects.Count)
					currentIndex = m_sortedObjects.Count - 1;
				CurrentIndex = currentIndex;
				if (m_sortedObjects.Count != cOrigSortObjects)
				{
					SendPropChangedOnListChange(CurrentIndex,
						SortedObjects, ListChangedEventArgs.ListChangedActions.Normal);
				}
			}
			finally
			{
				m_fUpdatingList = fUpdatingListOrig;
			}
		}
开发者ID:sillsdev,项目名称:WorldPad,代码行数:49,代码来源:RecordList.cs


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