From 5a1af7eccd97664d4666d286dc119f57eb97d151 Mon Sep 17 00:00:00 2001 From: Alessio Parma Date: Fri, 23 Jun 2017 18:10:14 +0200 Subject: [PATCH] removed dep on thrower --- .../CodeProject.ObjectPool.csproj | 19 ++++-- .../ParameterizedObjectPool.cs | 5 +- src/CodeProject.ObjectPool/PooledObject.cs | 67 ++++++++++--------- .../PooledObjectWrapper.cs | 9 ++- src/CodeProject.ObjectPool/TimedObjectPool.cs | 3 +- 5 files changed, 56 insertions(+), 47 deletions(-) diff --git a/src/CodeProject.ObjectPool/CodeProject.ObjectPool.csproj b/src/CodeProject.ObjectPool/CodeProject.ObjectPool.csproj index 4a0b1be..743f684 100644 --- a/src/CodeProject.ObjectPool/CodeProject.ObjectPool.csproj +++ b/src/CodeProject.ObjectPool/CodeProject.ObjectPool.csproj @@ -33,22 +33,27 @@ - - - - $(DefineConstants);NETSTD10;LIBLOG_PORTABLE $(PackageTargetFallback);dnxcore50 + + + + $(DefineConstants);NETSTD13;LIBLOG_PORTABLE $(PackageTargetFallback);dnxcore50 + + + + + - $(DefineConstants);NET35 + $(DefineConstants);NET35;HAS_SERIALIZABLE @@ -56,7 +61,7 @@ - $(DefineConstants);NET40 + $(DefineConstants);NET40;HAS_SERIALIZABLE @@ -65,7 +70,7 @@ - $(DefineConstants);NET45 + $(DefineConstants);NET45;HAS_SERIALIZABLE diff --git a/src/CodeProject.ObjectPool/ParameterizedObjectPool.cs b/src/CodeProject.ObjectPool/ParameterizedObjectPool.cs index 925f796..abb54b7 100644 --- a/src/CodeProject.ObjectPool/ParameterizedObjectPool.cs +++ b/src/CodeProject.ObjectPool/ParameterizedObjectPool.cs @@ -9,7 +9,6 @@ */ using CodeProject.ObjectPool.Core; -using PommaLabs.Thrower; using System; using System.Diagnostics; using System.Linq; @@ -69,7 +68,7 @@ public int MaximumPoolSize set { // Preconditions - Raise.ArgumentOutOfRangeException.If(value < 1, nameof(value), ErrorMessages.NegativeOrZeroMaximumPoolSize); + if (value < 1) throw new ArgumentOutOfRangeException(nameof(value), ErrorMessages.NegativeOrZeroMaximumPoolSize); _maximumPoolSize = value; } @@ -123,7 +122,7 @@ public ParameterizedObjectPool(Func factoryMethod) public ParameterizedObjectPool(int maximumPoolSize, Func factoryMethod) { // Preconditions - Raise.ArgumentOutOfRangeException.If(maximumPoolSize < 1, nameof(maximumPoolSize), ErrorMessages.NegativeOrZeroMaximumPoolSize); + if (maximumPoolSize < 1) throw new ArgumentOutOfRangeException(nameof(maximumPoolSize), ErrorMessages.NegativeOrZeroMaximumPoolSize); // Assigning properties Diagnostics = new ObjectPoolDiagnostics(); diff --git a/src/CodeProject.ObjectPool/PooledObject.cs b/src/CodeProject.ObjectPool/PooledObject.cs index 1ceb2b4..b0d57b3 100644 --- a/src/CodeProject.ObjectPool/PooledObject.cs +++ b/src/CodeProject.ObjectPool/PooledObject.cs @@ -9,13 +9,12 @@ */ using CodeProject.ObjectPool.Core; -using PommaLabs.Thrower.Goodies; using System; using System.Collections.Generic; #if !NET35 -using PommaLabs.Thrower.Logging; +using CodeProject.ObjectPool.Logging; #endif @@ -24,8 +23,11 @@ namespace CodeProject.ObjectPool /// /// PooledObject base class. /// +#if HAS_SERIALIZABLE [Serializable] - public abstract class PooledObject : EquatableObject, IDisposable +#endif + + public abstract class PooledObject : IDisposable, IEquatable { #region Logging @@ -190,34 +192,39 @@ private void HandleReAddingToPool(bool reRegisterForFinalization) #region Formatting and equality - /// - /// Returns all property (or field) values, along with their names, so that they can be - /// used to produce a meaningful . - /// - /// - /// All property (or field) values, along with their names, so that they can be used to - /// produce a meaningful . - /// - protected override IEnumerable> GetFormattingMembers() - { - yield return new KeyValuePair(nameof(PooledObjectInfo.Id), PooledObjectInfo.Id); - if (PooledObjectInfo.Payload != null) - { - yield return new KeyValuePair(nameof(PooledObjectInfo.Payload), PooledObjectInfo.Payload); - } - } - - /// - /// Returns all property (or field) values that should be used inside - /// or . - /// - /// - /// All property (or field) values that should be used inside - /// or . - /// - protected override IEnumerable GetIdentifyingMembers() + ///// + ///// Returns all property (or field) values, along with their names, so that they can be + ///// used to produce a meaningful . + ///// + ///// + ///// All property (or field) values, along with their names, so that they can be used to + ///// produce a meaningful . + ///// + //protected override IEnumerable> GetFormattingMembers() + //{ + // yield return new KeyValuePair(nameof(PooledObjectInfo.Id), PooledObjectInfo.Id); + // if (PooledObjectInfo.Payload != null) + // { + // yield return new KeyValuePair(nameof(PooledObjectInfo.Payload), PooledObjectInfo.Payload); + // } + //} + + ///// + ///// Returns all property (or field) values that should be used inside + ///// or . + ///// + ///// + ///// All property (or field) values that should be used inside + ///// or . + ///// + //protected override IEnumerable GetIdentifyingMembers() + //{ + // yield return PooledObjectInfo.Id; + //} + + public bool Equals(PooledObject other) { - yield return PooledObjectInfo.Id; + throw new NotImplementedException(); } #endregion Formatting and equality diff --git a/src/CodeProject.ObjectPool/PooledObjectWrapper.cs b/src/CodeProject.ObjectPool/PooledObjectWrapper.cs index 9c1ce86..eb84d1c 100644 --- a/src/CodeProject.ObjectPool/PooledObjectWrapper.cs +++ b/src/CodeProject.ObjectPool/PooledObjectWrapper.cs @@ -9,7 +9,6 @@ */ using CodeProject.ObjectPool.Core; -using PommaLabs.Thrower; using System; namespace CodeProject.ObjectPool @@ -17,7 +16,10 @@ namespace CodeProject.ObjectPool /// /// PooledObject wrapper, for classes which cannot inherit from that class. /// +#if HAS_SERIALIZABLE [Serializable] +#endif + public sealed class PooledObjectWrapper : PooledObject where T : class { /// @@ -27,10 +29,7 @@ public sealed class PooledObjectWrapper : PooledObject where T : class /// Given resource is null. public PooledObjectWrapper(T resource) { - // Preconditions - Raise.ArgumentNullException.IfIsNull(resource, nameof(resource), ErrorMessages.NullResource); - - InternalResource = resource; + InternalResource = resource ?? throw new ArgumentNullException(nameof(resource), ErrorMessages.NullResource); base.OnReleaseResources += () => OnReleaseResources?.Invoke(InternalResource); base.OnResetState += () => OnResetState?.Invoke(InternalResource); diff --git a/src/CodeProject.ObjectPool/TimedObjectPool.cs b/src/CodeProject.ObjectPool/TimedObjectPool.cs index 45677d0..05d5ddd 100644 --- a/src/CodeProject.ObjectPool/TimedObjectPool.cs +++ b/src/CodeProject.ObjectPool/TimedObjectPool.cs @@ -24,7 +24,6 @@ #if !NETSTD10 using CodeProject.ObjectPool.Core; -using PommaLabs.Thrower; using System; using System.Linq; using System.Threading; @@ -109,7 +108,7 @@ public TimedObjectPool(Func factoryMethod, TimeSpan timeout) public TimedObjectPool(int maximumPoolSize, Func factoryMethod, TimeSpan timeout) : base(maximumPoolSize, factoryMethod) { // Preconditions - Raise.ArgumentOutOfRangeException.IfIsLessOrEqual(timeout, TimeSpan.Zero, nameof(timeout), ErrorMessages.NegativeOrZeroTimeout); + if (timeout <= TimeSpan.Zero) throw new ArgumentOutOfRangeException(nameof(timeout), ErrorMessages.NegativeOrZeroTimeout); // Assigning properties. Timeout = timeout;