CopyTo() public method

public CopyTo ( Array array, int index ) : void
array Array
index int
return void
Ejemplo n.º 1
0
		/// <summary>
		/// Sorts the view of the underlying list based on the given <see cref="T:System.ComponentModel.ListSortDescriptionCollection"></see>.
		/// </summary>
		/// <param name="sorts">The <see cref="T:System.ComponentModel.ListSortDescriptionCollection"></see> containing the sorts to apply to the view.</param>
		public void ApplySort(ListSortDescriptionCollection sorts)
		{
			Lock();

			try
			{
				ListSortDescriptionCollection proposed;

				if (sorts == null)
					proposed = new ListSortDescriptionCollection();
				else
				{
					foreach (ListSortDescription desc in sorts)
						ValidateProperty(desc.PropertyDescriptor);

					ListSortDescription[] props = new ListSortDescription[sorts.Count];
					sorts.CopyTo(props, 0);
					proposed = new ListSortDescriptionCollection(props);
				}

				this.SortProperties = proposed;
			}
			finally
			{
				Unlock();
			}

			RaiseEvents();
		}
Ejemplo n.º 2
0
		private IComparer GetSortComparer(ListSortDescriptionCollection sortDescriptions)
		{
			bool needSubstitution = false;

			if (_sortSubstitutions.Count > 0)
			{
				foreach (ListSortDescription sortDescription in sortDescriptions)
				{
					if (_sortSubstitutions.ContainsKey(sortDescription.PropertyDescriptor.Name))
					{
						needSubstitution = true;
						break;
					}
				}

				if (needSubstitution)
				{
					ListSortDescription[] sorts = new ListSortDescription[sortDescriptions.Count];
					sortDescriptions.CopyTo(sorts, 0);

					for (int i = 0; i < sorts.Length; i++)
						if (_sortSubstitutions.ContainsKey(sorts[i].PropertyDescriptor.Name))
							sorts[i] = new ListSortDescription(((SortSubstitutionPair)_sortSubstitutions[sorts[i].PropertyDescriptor.Name]).Substitute, 
								                               sorts[i].SortDirection);

					sortDescriptions = new ListSortDescriptionCollection(sorts);
				}
			}

			return new SortListPropertyComparer(sortDescriptions);
		}