diff --git a/Src/FluentAssertions/Common/ReadOnlyNonGenericCollectionWrapper.cs b/Src/FluentAssertions/Common/ReadOnlyNonGenericCollectionWrapper.cs index f82dd73023..b829f8b68f 100644 --- a/Src/FluentAssertions/Common/ReadOnlyNonGenericCollectionWrapper.cs +++ b/Src/FluentAssertions/Common/ReadOnlyNonGenericCollectionWrapper.cs @@ -47,7 +47,7 @@ public ReadOnlyNonGenericCollectionWrapper(TCollection collection) public int Count => UnderlyingCollection.Count; - public bool IsReadOnly => true; + bool ICollection.IsReadOnly => true; public IEnumerator GetEnumerator() => UnderlyingCollection.Cast().GetEnumerator(); @@ -57,18 +57,9 @@ public ReadOnlyNonGenericCollectionWrapper(TCollection collection) public void CopyTo(TItem[] array, int arrayIndex) => UnderlyingCollection.CopyTo(array, arrayIndex); - /* + void ICollection.Add(TItem item) => throw new NotSupportedException(); - Mutation is not supported, but these methods must be implemented to satisfy ICollection: - * Add - * Clear - * Remove + void ICollection.Clear() => throw new NotSupportedException(); - */ - - public void Add(TItem item) => throw new NotSupportedException(); - - public void Clear() => throw new NotSupportedException(); - - public bool Remove(TItem item) => throw new NotSupportedException(); + bool ICollection.Remove(TItem item) => throw new NotSupportedException(); } diff --git a/Src/FluentAssertions/DataColumnCollectionAssertionExtensions.cs b/Src/FluentAssertions/DataColumnCollectionAssertionExtensions.cs index 67c2af72db..68f6e57166 100644 --- a/Src/FluentAssertions/DataColumnCollectionAssertionExtensions.cs +++ b/Src/FluentAssertions/DataColumnCollectionAssertionExtensions.cs @@ -73,7 +73,7 @@ public static AndConstraint> NotBeSameAs Guard.ThrowIfArgumentIsNull( unexpected, nameof(unexpected), "Cannot verify same reference against a collection (use NotBeNull instead?)."); - if (assertion.Subject is ReadOnlyNonGenericCollectionWrapper wrapper) + if (assertion.Subject is ICollectionWrapper wrapper) { var actualSubject = wrapper.UnderlyingCollection; diff --git a/Src/FluentAssertions/DataRowCollectionAssertionExtensions.cs b/Src/FluentAssertions/DataRowCollectionAssertionExtensions.cs index 094562a800..ef82cee119 100644 --- a/Src/FluentAssertions/DataRowCollectionAssertionExtensions.cs +++ b/Src/FluentAssertions/DataRowCollectionAssertionExtensions.cs @@ -28,7 +28,7 @@ public static AndConstraint> BeSameAs( this GenericCollectionAssertions assertion, DataRowCollection expected, string because = "", params object[] becauseArgs) { - if (assertion.Subject is ReadOnlyNonGenericCollectionWrapper wrapper) + if (assertion.Subject is ICollectionWrapper wrapper) { var actualSubject = wrapper.UnderlyingCollection; @@ -68,7 +68,7 @@ public static AndConstraint> NotBeSameAs( this GenericCollectionAssertions assertion, DataRowCollection unexpected, string because = "", params object[] becauseArgs) { - if (assertion.Subject is ReadOnlyNonGenericCollectionWrapper wrapper) + if (assertion.Subject is ICollectionWrapper wrapper) { var actualSubject = wrapper.UnderlyingCollection; diff --git a/Src/FluentAssertions/DataTableCollectionAssertionExtensions.cs b/Src/FluentAssertions/DataTableCollectionAssertionExtensions.cs index 4a01fb71dc..e5364a53d5 100644 --- a/Src/FluentAssertions/DataTableCollectionAssertionExtensions.cs +++ b/Src/FluentAssertions/DataTableCollectionAssertionExtensions.cs @@ -25,7 +25,7 @@ public static AndConstraint> BeSameAs( this GenericCollectionAssertions assertion, DataTableCollection expected, string because = "", params object[] becauseArgs) { - if (assertion.Subject is ReadOnlyNonGenericCollectionWrapper wrapper) + if (assertion.Subject is ICollectionWrapper wrapper) { var actualSubject = wrapper.UnderlyingCollection; @@ -65,7 +65,7 @@ public static AndConstraint> NotBeSameAs( this GenericCollectionAssertions assertion, DataTableCollection unexpected, string because = "", params object[] becauseArgs) { - if (assertion.Subject is ReadOnlyNonGenericCollectionWrapper wrapper) + if (assertion.Subject is ICollectionWrapper wrapper) { var actualSubject = wrapper.UnderlyingCollection; diff --git a/Src/FluentAssertions/Equivalency/Field.cs b/Src/FluentAssertions/Equivalency/Field.cs index d82f1e46bc..e44a523d20 100644 --- a/Src/FluentAssertions/Equivalency/Field.cs +++ b/Src/FluentAssertions/Equivalency/Field.cs @@ -46,16 +46,6 @@ public object GetValue(object obj) public CSharpAccessModifier SetterAccessibility => fieldInfo.GetCSharpAccessModifier(); - public bool IsBrowsable - { - get - { - if (isBrowsable == null) - { - isBrowsable = fieldInfo.GetCustomAttribute() is not { State: EditorBrowsableState.Never }; - } - - return isBrowsable.Value; - } - } + public bool IsBrowsable => + isBrowsable ??= fieldInfo.GetCustomAttribute() is not { State: EditorBrowsableState.Never }; } diff --git a/Src/FluentAssertions/Events/EventMonitor.cs b/Src/FluentAssertions/Events/EventMonitor.cs index 60cdceb893..eb63581fcf 100644 --- a/Src/FluentAssertions/Events/EventMonitor.cs +++ b/Src/FluentAssertions/Events/EventMonitor.cs @@ -16,8 +16,7 @@ internal class EventMonitor : IMonitor { private readonly WeakReference subject; - private readonly ConcurrentDictionary recorderMap = - new ConcurrentDictionary(); + private readonly ConcurrentDictionary recorderMap = new(); public EventMonitor(object eventSource, Func utcNow) {