Removed AcquiringCollection because in hindsight, the design added little value and even required some workarounds to be fully usable in the classes it was intended to simplify; added mono/linux build for the assembly

git-svn-id: file:///srv/devel/repo-conversion/nusu@42 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
Markus Ewald 2007-07-24 19:51:51 +00:00
parent cf92f22b31
commit 9f4751ae39
4 changed files with 164 additions and 125 deletions

View File

@ -65,10 +65,6 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Source\Collections\AcquiringCollection.cs">
<XNAUseContentPipeline>false</XNAUseContentPipeline>
<Name>AcquiringCollection</Name>
</Compile>
<Compile Include="Source\Collections\ItemEventArgs.cs">
<XNAUseContentPipeline>false</XNAUseContentPipeline>
<Name>ItemEventArgs</Name>

81
Nuclex.Support.build Normal file
View File

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="utf-8" ?>
<project
xmlns="http://nant.sf.net/schemas/nant-0.85.win32.net-1.0.xsd"
name="Nuclex.Support"
default="compile"
>
<!--
This property can be overriden on the command line and controls whether
we build in debug or release mode
-->
<property overwrite="false" name="configuration" value="release" />
<!--
Set Optimization flags depending on the selected build configuration
-->
<property if="${configuration == 'release'}" name="optimize" value="true" />
<property if="${configuration == 'debug'}" name="optimize" value="false" />
<!--
Enable or disable debug informations depending on the selected build configuration
-->
<property if="${configuration == 'release'}" name="debug" value="None" />
<property if="${configuration == 'debug'}" name="debug" value="Full" />
<!--
Compile the sources to an assembly
-->
<target name="compile" description="Compile the assembly">
<!-- Display the exactt build configuration we're using for this compile -->
<echo message="optimization enabled: ${optimize}" />
<echo message="debugging informations: ${debug}" />
<!-- Create the output directory if it doesn't exist yet -->
<mkdir dir="bin/${configuration}" />
<!-- The compiling itself -->
<csc
target="library"
output="bin/${configuration}/Nuclex.Support.dll"
doc="bin/${configuration}/Nuclex.Support.xml"
optimize="${optimize}"
debug="${debug}"
>
<references>
<include
asis="true"
name="References/nunit/${nant.settings.currentframework}/nunit.framework.dll"
/>
<!--
<include
asis="true"
name="../Nuclex.Math/bin/${configuration}/Nuclex.Math.dll"
/>
-->
<include
asis="true"
name="../xna/Microsoft.Xna.Framework.dll"
/>
</references>
<sources>
<include name="Source/**/*.cs" />
</sources>
</csc>
</target>
<!--
Removes all intermediate files created by the build process
-->
<target name="clean" description="Remove intermediate files">
<delete dir="bin" />
<delete dir="obj" />
</target>
</project>

View File

@ -1,110 +0,0 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
published by the IBM Corporation; either version 1.0 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
IBM Common Public License for more details.
You should have received a copy of the IBM Common Public
License along with this library
*/
#endregion
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace Nuclex.Support.Collections {
/// <summary>Generic collection of progressions</summary>
public class AcquiringCollection<ItemType> : Collection<ItemType> {
/// <summary>
/// Initializes a new instance of the ObservableCollection class that is empty.
/// </summary>
public AcquiringCollection() : base() { }
/// <summary>
/// Initializes a new instance of the ObservableCollection class as a wrapper
/// for the specified list.
/// </summary>
/// <param name="list">The list that is wrapped by the new collection.</param>
/// <exception cref="System.ArgumentNullException">
/// List is null.
/// </exception>
public AcquiringCollection(IList<ItemType> list) : base(list) { }
/// <summary>Removes all elements from the Collection</summary>
protected override void ClearItems() {
OnClearing();
base.ClearItems();
}
/// <summary>
/// Inserts an element into the ProgressionCollection at the specified index
/// </summary>
/// <param name="index">
/// The object to insert. The value can be null for reference types.
/// </param>
/// <param name="item">The zero-based index at which item should be inserted</param>
protected override void InsertItem(int index, ItemType item) {
base.InsertItem(index, item);
OnAdded(item);
}
/// <summary>
/// Removes the element at the specified index of the ProgressionCollection
/// </summary>
/// <param name="index">The zero-based index of the element to remove</param>
protected override void RemoveItem(int index) {
ItemType item = base[index];
base.RemoveItem(index);
OnRemoved(item);
}
/// <summary>Replaces the element at the specified index</summary>
/// <param name="index">
/// The new value for the element at the specified index. The value can be null
/// for reference types
/// </param>
/// <param name="item">The zero-based index of the element to replace</param>
protected override void SetItem(int index, ItemType item) {
ItemType oldItem = base[index];
base.SetItem(index, item);
OnRemoved(oldItem);
OnAdded(item);
}
/// <summary>Called when an item has been added to the collection</summary>
/// <param name="item">Item that has been added to the collection</param>
protected virtual void OnAdded(ItemType item) { }
/// <summary>Called when an item has been removed from the collection</summary>
/// <param name="item">Item that has been removed from the collection</param>
protected virtual void OnRemoved(ItemType item) { }
/// <summary>Called when the collection is being cleared</summary>
/// <remarks>
/// Instead of calling the OnRemoved() method for each item in the collection when
/// it is being cleared, this variant only triggers the OnClearing() method
/// to allow the implementer some room for optimizations.
/// </remarks>
protected virtual void OnClearing() { }
}
} // namespace Nuclex.Support.Collections

View File

@ -23,13 +23,36 @@ using System.Collections.ObjectModel;
namespace Nuclex.Support.Collections {
/// <summary>Collection which fires events when items are added or removed</summary>
public class ObservableCollection<ItemType> : AcquiringCollection<ItemType> {
/// <summary>Generic collection of progressions</summary>
public class ObservableCollection<ItemType> : Collection<ItemType> {
#region class ItemEventArgs
/// <summary>Arguments class for events that need to pass a progression</summary>
public class ItemEventArgs : EventArgs {
/// <summary>Initializes a new event arguments supplier</summary>
/// <param name="item">Item to be supplied to the event handler</param>
public ItemEventArgs(ItemType item) {
this.item = item;
}
/// <summary>Obtains the collection item the event arguments are carrying</summary>
public ItemType Item {
get { return this.item; }
}
/// <summary>Item that's passed to the event handler</summary>
private ItemType item;
}
#endregion // class ItemEventArgs
/// <summary>Raised when an item has been added to the collection</summary>
public event EventHandler<ItemEventArgs<ItemType>> ItemAdded;
public event EventHandler<ItemEventArgs> ItemAdded;
/// <summary>Raised when an item is removed from the collection</summary>
public event EventHandler<ItemEventArgs<ItemType>> ItemRemoved;
public event EventHandler<ItemEventArgs> ItemRemoved;
/// <summary>Raised the collection is about to be cleared</summary>
public event EventHandler Clearing;
@ -43,25 +66,74 @@ namespace Nuclex.Support.Collections {
/// for the specified list.
/// </summary>
/// <param name="list">The list that is wrapped by the new collection.</param>
/// <exception cref="System.ArgumentNullException">List is null.</exception>
/// <exception cref="System.ArgumentNullException">
/// List is null.
/// </exception>
public ObservableCollection(IList<ItemType> list) : base(list) { }
/// <summary>Removes all elements from the Collection</summary>
protected override void ClearItems() {
OnClearing();
base.ClearItems();
}
/// <summary>
/// Inserts an element into the ProgressionCollection at the specified index
/// </summary>
/// <param name="index">
/// The object to insert. The value can be null for reference types.
/// </param>
/// <param name="item">The zero-based index at which item should be inserted</param>
protected override void InsertItem(int index, ItemType item) {
base.InsertItem(index, item);
OnAdded(item);
}
/// <summary>
/// Removes the element at the specified index of the ProgressionCollection
/// </summary>
/// <param name="index">The zero-based index of the element to remove</param>
protected override void RemoveItem(int index) {
ItemType item = base[index];
base.RemoveItem(index);
OnRemoved(item);
}
/// <summary>Replaces the element at the specified index</summary>
/// <param name="index">
/// The new value for the element at the specified index. The value can be null
/// for reference types
/// </param>
/// <param name="item">The zero-based index of the element to replace</param>
protected override void SetItem(int index, ItemType item) {
ItemType oldItem = base[index];
base.SetItem(index, item);
OnRemoved(oldItem);
OnAdded(item);
}
/// <summary>Fires the 'ItemAdded' event</summary>
/// <param name="item">Item that has been added to the collection</param>
protected override void OnAdded(ItemType item) {
protected virtual void OnAdded(ItemType item) {
if(ItemAdded != null)
ItemAdded(this, new ItemEventArgs<ItemType>(item));
ItemAdded(this, new ItemEventArgs(item));
}
/// <summary>Fires the 'ItemRemoved' event</summary>
/// <param name="item">Item that has been removed from the collection</param>
protected override void OnRemoved(ItemType item) {
protected virtual void OnRemoved(ItemType item) {
if(ItemRemoved != null)
ItemRemoved(this, new ItemEventArgs<ItemType>(item));
ItemRemoved(this, new ItemEventArgs(item));
}
/// <summary>Fires the 'Clearing' event</summary>
protected override void OnClearing() {
protected virtual void OnClearing() {
if(Clearing != null)
Clearing(this, EventArgs.Empty);
}