Click here to Skip to main content
15,896,207 members
Articles / Programming Languages / C# 4.0

The List Trifecta, Part 2

Rate me:
Please Sign up or sign in to vote.
5.00/5 (4 votes)
7 Sep 2013LGPL310 min read 28.7K   317   12  
The BDictionary is like a Dictionary mashed up with List<T>. BList and BMultiMap also say hello.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using System.Diagnostics;

namespace Loyc.Collections
{
	/// <summary>Contains information about how a collection is about to change.</summary>
	/// <typeparam name="T">Type of element in the collection</typeparam>
	/// <remarks>
	/// In contrast to <see cref="NotifyCollectionChangedEventArgs"/>, this object
	/// represents changes that are about to happen, not changes that have happened
	/// already.
	/// </remarks>
	/// <seealso cref="INotifyListChanging{T}"/>
	[Serializable]
	public class ListChangeInfo<T> : EventArgs
	{
		/// <summary>Initializes the members of <see cref="ListChangeInfo{T}"/>.</summary>
		public ListChangeInfo(NotifyCollectionChangedAction action, int index, int sizeChange, IListSource<T> newItems)
		{
			Action = action;
			Index = index;
			SizeChange = sizeChange;
			NewItems = newItems;
			Debug.Assert(
				(action == NotifyCollectionChangedAction.Add && newItems != null && NewItems.Count == sizeChange) ||
				(action == NotifyCollectionChangedAction.Remove && newItems == null && sizeChange < 0) ||
				(action == NotifyCollectionChangedAction.Replace && newItems != null && sizeChange == 0) ||
				(action == NotifyCollectionChangedAction.Move && sizeChange == 0) ||
				(action == NotifyCollectionChangedAction.Reset));
		}

		/// <summary>Gets a value that indicates the type of change being made to 
		/// the collection.</summary>
		public readonly NotifyCollectionChangedAction Action;

		/// <summary>Gets the index at which the add, remove, or change operation starts.</summary>
		public readonly int Index;

		/// <summary>Gets the amount by which the collection size changes. When 
		/// items are being added, this is positive, and when items are being
		/// removed, this is negative. This is 0 when existing items are only being 
		/// replaced.</summary>
		public readonly int SizeChange;
		
		/// <summary>Represents either new items that are being added to the 
		/// collection, or items that are about to replace existing items in 
		/// the collection. This member is null or empty when items are being 
		/// removed.</summary>
		public readonly IListSource<T> NewItems;
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Software Developer None
Canada Canada
Since I started programming when I was 11, I wrote the SNES emulator "SNEqr", the FastNav mapping component, the Enhanced C# programming language (in progress), the parser generator LLLPG, and LES, a syntax to help you start building programming languages, DSLs or build systems.

My overall focus is on the Language of your choice (Loyc) initiative, which is about investigating ways to improve interoperability between programming languages and putting more power in the hands of developers. I'm also seeking employment.

Comments and Discussions