Added six separate constructors to avoid default parameters (which aren't supported on Windows Phone 7 or the Xbox 360)

git-svn-id: file:///srv/devel/repo-conversion/nusu@269 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
Markus Ewald 2012-03-08 11:31:24 +00:00
parent c91a082e84
commit 58a1652749
2 changed files with 49 additions and 15 deletions

View file

@ -50,22 +50,45 @@ namespace Nuclex.Support.Collections {
/// <summary>Default number of recyclable objects the pool will store</summary>
public const int DefaultPoolSize = 64;
/// <summary>Initializes a new pool using the default capacity</summary>
public Pool() : this(DefaultPoolSize, null, null) { }
/// <summary>Initializes a new pool using the default capacity</summary>
/// <param name="createNewDelegate">Delegate that will be used to create new items</param>
public Pool(Func<TItem> createNewDelegate) :
this(DefaultPoolSize, createNewDelegate, null) { }
/// <summary>Initializes a new pool using the default capacity</summary>
/// <param name="createNewDelegate">Delegate that will be used to create new items</param>
/// <param name="recycleDelegate">Delegate that will be used to recycle items</param>
public Pool(Func<TItem> createNewDelegate = null, Action<TItem> recycleDelegate = null) :
public Pool(Func<TItem> createNewDelegate, Action<TItem> recycleDelegate) :
this(DefaultPoolSize, createNewDelegate, recycleDelegate) { }
/// <summary>Initializes a new pool using a user-specified capacity</summary>
/// <param name="capacity">Capacity of the pool</param>
public Pool(int capacity) :
this(capacity, null, null) { }
/// <summary>Initializes a new pool using a user-specified capacity</summary>
/// <param name="capacity">Capacity of the pool</param>
/// <param name="createNewDelegate">Delegate that will be used to create new items</param>
public Pool(int capacity, Func<TItem> createNewDelegate) :
this(capacity, createNewDelegate, null) { }
/// <summary>Initializes a new pool using a user-specified capacity</summary>
/// <param name="capacity">Capacity of the pool</param>
/// <param name="createNewDelegate">Delegate that will be used to create new items</param>
/// <param name="recycleDelegate">Delegate that will be used to recycle items</param>
public Pool(
int capacity, Func<TItem> createNewDelegate = null, Action<TItem> recycleDelegate = null
) {
public Pool(int capacity, Func<TItem> createNewDelegate, Action<TItem> recycleDelegate) {
Capacity = capacity;
if(createNewDelegate == null) {
if(!typeof(TItem).HasDefaultConstructor()) {
throw new ArgumentException(
"Type " + typeof(TItem).Name + " has no default constructor and " +
"requires a custom 'create instance' delegate"
);
}
createNewDelegate = new Func<TItem>(Activator.CreateInstance<TItem>);
}
if(recycleDelegate == null) {