diff --git a/Source/Core.UnitTests/Collections/Generic/ThreadSafeQueueTest.cs b/Source/Core.UnitTests/Collections/Generic/ThreadSafeQueueTest.cs index d2c2609..d4fd6b0 100644 --- a/Source/Core.UnitTests/Collections/Generic/ThreadSafeQueueTest.cs +++ b/Source/Core.UnitTests/Collections/Generic/ThreadSafeQueueTest.cs @@ -282,7 +282,7 @@ public void It_throws_exception_when_offset_is_less_than_count() public class When_ICollection_IsSynchronized_is_called { [Test] - public void Itreturns_true() + public void It_returns_true() { Assert.That(((ICollection)new ThreadSafeQueue()).IsSynchronized, Is.True); } diff --git a/Source/Core.UnitTests/EnsureTest.cs b/Source/Core.UnitTests/EnsureTest.cs index 88b3d51..d895120 100644 --- a/Source/Core.UnitTests/EnsureTest.cs +++ b/Source/Core.UnitTests/EnsureTest.cs @@ -51,11 +51,22 @@ public void It_does_not_throw_exception_when_input_is_not_null() } [Test] - public void It_throws_exception_when_input_is_null_or_whitespace() + public void It_throws_exception_when_input_is_empty() { - Assert.Throws(() => Ensure.IsNotNullOrWhitespace("It_throws_exception_when_input_is_null_or_whitespace", null)); - Assert.Throws(() => Ensure.IsNotNullOrWhitespace("It_throws_exception_when_input_is_null_or_whitespace", " ")); - Assert.Throws(() => Ensure.IsNotNullOrWhitespace("It_throws_exception_when_input_is_null_or_whitespace", "\t")); + Assert.Throws(() => Ensure.IsNotNullOrWhitespace("It_throws_exception_when_input_is_empty", "")); + } + + [Test] + public void It_throws_exception_when_input_is_null() + { + Assert.Throws(() => Ensure.IsNotNullOrWhitespace("It_throws_exception_when_input_is_null", null)); + } + + [Test] + public void It_throws_exception_when_input_is_whitespace() + { + Assert.Throws(() => Ensure.IsNotNullOrWhitespace("It_throws_exception_when_input_is_whitespace", " ")); + Assert.Throws(() => Ensure.IsNotNullOrWhitespace("It_throws_exception_when_input_is_whitespace", "\t")); } } diff --git a/Source/Core/CCSWE.Core.nuspec b/Source/Core/CCSWE.Core.nuspec index b6104e7..d4aba7e 100644 --- a/Source/Core/CCSWE.Core.nuspec +++ b/Source/Core/CCSWE.Core.nuspec @@ -9,8 +9,13 @@ https://github.com/CoryCharlton/CCSWE.Core/blob/master/LICENSE.md https://github.com/CoryCharlton/CCSWE.Core false - Just a bunch of C# .NET classes and extension methods I find useful - Minor bug fixes + Just a bunch of C# .NET classes and extension methods I find useful. + + - Improved ThreadSafeQueue performance + - Fixed a bug where performing the set operation on the SynchronizedObservableCollection indexer might fail + - Added Ensure class + - General code cleanup and documentation improvements + Copyright 2016 Utilities Threading Collections AppSettings Extensions ThreadPool ObservableCollection diff --git a/Source/Core/Collections/Generic/ThreadSafeQueue`1.cs b/Source/Core/Collections/Generic/ThreadSafeQueue`1.cs index 522fe36..28f5cfb 100644 --- a/Source/Core/Collections/Generic/ThreadSafeQueue`1.cs +++ b/Source/Core/Collections/Generic/ThreadSafeQueue`1.cs @@ -73,9 +73,15 @@ public int Count } } - bool ICollection.IsSynchronized => true; + /// Gets a value indicating whether access to the is synchronized (thread safe). + /// true if access to the is synchronized (thread safe); otherwise, false. + protected bool IsSynchronized => true; - object ICollection.SyncRoot + bool ICollection.IsSynchronized => IsSynchronized; + + /// Gets an object that can be used to synchronize access to the . + /// An object that can be used to synchronize access to the . + protected object SyncRoot { get { @@ -87,6 +93,8 @@ object ICollection.SyncRoot return _syncRoot; } } + + object ICollection.SyncRoot => SyncRoot; #endregion #region Protected Methods @@ -224,9 +232,7 @@ public void Enqueue(T item) } /// Adds the elements of the specified collection to the end of the . - #pragma warning disable 1584,1711,1572,1581,1580 - /// The collection whose elements should be added to the end of the . The collection itself cannot be null, but it can contain elements that are null, if type is a reference type. - #pragma warning restore 1584,1711,1572,1581,1580 + /// The collection whose elements should be added to the end of the . The collection itself cannot be null, but it can contain elements that are null, if type is a reference type. /// /// is null. [SuppressMessage("ReSharper", "PossibleMultipleEnumeration")] diff --git a/Source/Core/Collections/ObjectModel/SynchronizedObservableCollection`1.cs b/Source/Core/Collections/ObjectModel/SynchronizedObservableCollection`1.cs index c7d39eb..b82cc34 100644 --- a/Source/Core/Collections/ObjectModel/SynchronizedObservableCollection`1.cs +++ b/Source/Core/Collections/ObjectModel/SynchronizedObservableCollection`1.cs @@ -60,13 +60,16 @@ public SynchronizedObservableCollection(IEnumerable collection, Synchronizati #endregion #region Private Fields + [NonSerialized] private readonly SynchronizationContext _context; private bool _isDisposed; private readonly IList _items = new List(); + [NonSerialized] private readonly ReaderWriterLockSlim _itemsLocker = new ReaderWriterLockSlim(); - [NonSerialized] private object _syncRoot; - + [NonSerialized] private readonly SimpleMonitor _monitor = new SimpleMonitor(); + [NonSerialized] + private object _syncRoot; #endregion #region Events @@ -84,15 +87,29 @@ event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged #endregion #region Private Properties - bool IList.IsFixedSize => false; + /// Gets a value indicating whether the . + /// true if the has a fixed size; otherwise, false. + protected bool IsFixedSize => false; + + bool IList.IsFixedSize => IsFixedSize; + + /// Gets a value indicating whether the is read-only. + /// true if the is read-only; otherwise, false. + protected bool IsReadOnly => false; - bool ICollection.IsReadOnly => false; + bool ICollection.IsReadOnly => IsReadOnly; - bool IList.IsReadOnly => false; + bool IList.IsReadOnly => IsReadOnly; - bool ICollection.IsSynchronized => true; + /// Gets a value indicating whether access to the is synchronized (thread safe). + /// true if access to the is synchronized (thread safe); otherwise, false. + protected bool IsSynchronized => true; - object ICollection.SyncRoot + bool ICollection.IsSynchronized => IsSynchronized; + + /// Gets an object that can be used to synchronize access to the . + /// An object that can be used to synchronize access to the . + protected object SyncRoot { get { @@ -123,6 +140,8 @@ object ICollection.SyncRoot } } + object ICollection.SyncRoot => SyncRoot; + object IList.this[int index] { get { return this[index]; } diff --git a/Source/Core/Collections/ObjectModel/SynchronizedReadOnlyObservableCollection`1.cs b/Source/Core/Collections/ObjectModel/SynchronizedReadOnlyObservableCollection`1.cs index b20618a..5f180b5 100644 --- a/Source/Core/Collections/ObjectModel/SynchronizedReadOnlyObservableCollection`1.cs +++ b/Source/Core/Collections/ObjectModel/SynchronizedReadOnlyObservableCollection`1.cs @@ -51,6 +51,7 @@ public SynchronizedReadOnlyObservableCollection(SynchronizedObservableCollection #endregion #region Private Fields + [NonSerialized] private readonly SynchronizationContext _context; #endregion diff --git a/Source/Core/Properties/AssemblyVersion.cs b/Source/Core/Properties/AssemblyVersion.cs index b3cdc6f..5a816e0 100644 --- a/Source/Core/Properties/AssemblyVersion.cs +++ b/Source/Core/Properties/AssemblyVersion.cs @@ -5,5 +5,5 @@ using System.Reflection; -[assembly: AssemblyVersion("2.0.348.1311")] -[assembly: AssemblyFileVersion("2.0.348.1311")] +[assembly: AssemblyVersion("2.0.348.3734")] +[assembly: AssemblyFileVersion("2.0.348.3734")]