Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code cleanups #1973

Merged
merged 4 commits into from Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 4 additions & 13 deletions Src/FluentAssertions/Common/ReadOnlyNonGenericCollectionWrapper.cs
Expand Up @@ -47,7 +47,7 @@ public ReadOnlyNonGenericCollectionWrapper(TCollection collection)

public int Count => UnderlyingCollection.Count;

public bool IsReadOnly => true;
bool ICollection<TItem>.IsReadOnly => true;

public IEnumerator<TItem> GetEnumerator() => UnderlyingCollection.Cast<TItem>().GetEnumerator();

Expand All @@ -57,18 +57,9 @@ public ReadOnlyNonGenericCollectionWrapper(TCollection collection)

public void CopyTo(TItem[] array, int arrayIndex) => UnderlyingCollection.CopyTo(array, arrayIndex);

/*
void ICollection<TItem>.Add(TItem item) => throw new NotSupportedException();

Mutation is not supported, but these methods must be implemented to satisfy ICollection<T>:
* Add
* Clear
* Remove
void ICollection<TItem>.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<TItem>.Remove(TItem item) => throw new NotSupportedException();
}
Expand Up @@ -73,7 +73,7 @@ public static class DataColumnCollectionAssertionExtensions
Guard.ThrowIfArgumentIsNull(
unexpected, nameof(unexpected), "Cannot verify same reference against a <null> collection (use NotBeNull instead?).");

if (assertion.Subject is ReadOnlyNonGenericCollectionWrapper<DataColumnCollection, DataColumn> wrapper)
if (assertion.Subject is ICollectionWrapper<DataColumnCollection> wrapper)
{
var actualSubject = wrapper.UnderlyingCollection;

Expand Down
4 changes: 2 additions & 2 deletions Src/FluentAssertions/DataRowCollectionAssertionExtensions.cs
Expand Up @@ -28,7 +28,7 @@ public static class DataRowCollectionAssertionExtensions
this GenericCollectionAssertions<DataRow> assertion, DataRowCollection expected, string because = "",
params object[] becauseArgs)
{
if (assertion.Subject is ReadOnlyNonGenericCollectionWrapper<DataRowCollection, DataRow> wrapper)
if (assertion.Subject is ICollectionWrapper<DataRowCollection> wrapper)
{
var actualSubject = wrapper.UnderlyingCollection;

Expand Down Expand Up @@ -68,7 +68,7 @@ public static class DataRowCollectionAssertionExtensions
this GenericCollectionAssertions<DataRow> assertion, DataRowCollection unexpected, string because = "",
params object[] becauseArgs)
{
if (assertion.Subject is ReadOnlyNonGenericCollectionWrapper<DataRowCollection, DataRow> wrapper)
if (assertion.Subject is ICollectionWrapper<DataRowCollection> wrapper)
{
var actualSubject = wrapper.UnderlyingCollection;

Expand Down
Expand Up @@ -25,7 +25,7 @@ public static class DataTableCollectionAssertionExtensions
this GenericCollectionAssertions<DataTable> assertion, DataTableCollection expected, string because = "",
params object[] becauseArgs)
{
if (assertion.Subject is ReadOnlyNonGenericCollectionWrapper<DataTableCollection, DataTable> wrapper)
if (assertion.Subject is ICollectionWrapper<DataTableCollection> wrapper)
{
var actualSubject = wrapper.UnderlyingCollection;

Expand Down Expand Up @@ -65,7 +65,7 @@ public static class DataTableCollectionAssertionExtensions
this GenericCollectionAssertions<DataTable> assertion, DataTableCollection unexpected, string because = "",
params object[] becauseArgs)
{
if (assertion.Subject is ReadOnlyNonGenericCollectionWrapper<DataTableCollection, DataTable> wrapper)
if (assertion.Subject is ICollectionWrapper<DataTableCollection> wrapper)
{
var actualSubject = wrapper.UnderlyingCollection;

Expand Down
14 changes: 2 additions & 12 deletions Src/FluentAssertions/Equivalency/Field.cs
Expand Up @@ -46,16 +46,6 @@ public object GetValue(object obj)

public CSharpAccessModifier SetterAccessibility => fieldInfo.GetCSharpAccessModifier();

public bool IsBrowsable
{
get
{
if (isBrowsable == null)
{
isBrowsable = fieldInfo.GetCustomAttribute<EditorBrowsableAttribute>() is not { State: EditorBrowsableState.Never };
}

return isBrowsable.Value;
}
}
public bool IsBrowsable =>
isBrowsable ??= fieldInfo.GetCustomAttribute<EditorBrowsableAttribute>() is not { State: EditorBrowsableState.Never };
}
3 changes: 1 addition & 2 deletions Src/FluentAssertions/Events/EventMonitor.cs
Expand Up @@ -16,8 +16,7 @@ internal class EventMonitor<T> : IMonitor<T>
{
private readonly WeakReference subject;

private readonly ConcurrentDictionary<string, EventRecorder> recorderMap =
new ConcurrentDictionary<string, EventRecorder>();
private readonly ConcurrentDictionary<string, EventRecorder> recorderMap = new();

public EventMonitor(object eventSource, Func<DateTime> utcNow)
{
Expand Down