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

Analyzer cleanups #2250

Merged
merged 3 commits into from
Aug 11, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal void Append(string symbols)
while (symbolEnumerator.MoveNext() && parsingState != ParsingState.Done)
{
var hasParsingStrategyWaitingForEndContext = priorityOrderedParsingStrategies
.Any(s => s.IsWaitingForContextEnd());
.Exists(s => s.IsWaitingForContextEnd());

parsingState = ParsingState.InProgress;

Expand Down
4 changes: 2 additions & 2 deletions Src/FluentAssertions/Common/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ public static IEnumerable<TAttribute> GetCustomAttributes<TAttribute>(this Membe
return GetCustomAttributes<TAttribute>(type, inherit).Where(isMatchingAttribute);
}

private static IEnumerable<TAttribute> GetCustomAttributes<TAttribute>(this Type type, bool inherit = false)
private static TAttribute[] GetCustomAttributes<TAttribute>(this Type type, bool inherit = false)
where TAttribute : Attribute
{
return (IEnumerable<TAttribute>)type.GetCustomAttributes(typeof(TAttribute), inherit);
return (TAttribute[])type.GetCustomAttributes(typeof(TAttribute), inherit);
}

private static IEnumerable<TAttribute> GetCustomAttributes<TAttribute>(Type type,
Expand Down
2 changes: 1 addition & 1 deletion Src/FluentAssertions/Common/TypeMemberReflector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private static List<FieldInfo> GetFieldsFromHierarchy(Type typeToReflect, Member
{
foreach (var memberInfo in getMembers(typeToReflect))
{
if (members.All(mi => mi.Name != memberInfo.Name))
if (members.TrueForAll(mi => mi.Name != memberInfo.Name))
{
members.Add(memberInfo);
}
Expand Down
3 changes: 1 addition & 2 deletions Src/FluentAssertions/Equivalency/ConversionSelector.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using FluentAssertions.Common;
Expand Down Expand Up @@ -83,7 +82,7 @@ public bool RequiresConversion(Comparands comparands, INode currentNode)

var objectInfo = new ObjectInfo(comparands, currentNode);

return inclusions.Any(p => p.Predicate(objectInfo)) && !exclusions.Any(p => p.Predicate(objectInfo));
return inclusions.Exists(p => p.Predicate(objectInfo)) && !exclusions.Exists(p => p.Predicate(objectInfo));
}

public override string ToString()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using FluentAssertions.Common;
Expand Down Expand Up @@ -33,7 +32,7 @@ public IncludeMemberByPredicateSelectionRule(Expression<Func<IMemberInfo, bool>>
{
IMember member = MemberFactory.Create(memberInfo, currentNode);

if (predicate(new MemberToMemberInfoAdapter(member)) && !members.Any(p => p.IsEquivalentTo(member)))
if (predicate(new MemberToMemberInfoAdapter(member)) && !members.Exists(p => p.IsEquivalentTo(member)))
{
members.Add(member);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using FluentAssertions.Common;
Expand Down Expand Up @@ -111,7 +110,7 @@ IEnumerable<IMemberSelectionRule> IEquivalencyAssertionOptions.SelectionRules
{
get
{
bool hasConflictingRules = selectionRules.Any(rule => rule.IncludesMembers);
bool hasConflictingRules = selectionRules.Exists(rule => rule.IncludesMembers);

if (includedProperties.HasFlag(MemberVisibility.Public) && !hasConflictingRules)
{
Expand Down Expand Up @@ -187,19 +186,19 @@ EqualityStrategy IEquivalencyAssertionOptions.GetEqualityStrategy(Type type)
// be aware if the cache must be cleared on mutating the members.
return equalityStrategyCache.GetOrAdd(type, typeKey =>
{
if (!typeKey.IsPrimitive && referenceTypes.Count > 0 && referenceTypes.Any(t => typeKey.IsSameOrInherits(t)))
if (!typeKey.IsPrimitive && referenceTypes.Count > 0 && referenceTypes.Exists(t => typeKey.IsSameOrInherits(t)))
{
return EqualityStrategy.ForceMembers;
}
else if (valueTypes.Count > 0 && valueTypes.Any(t => typeKey.IsSameOrInherits(t)))
else if (valueTypes.Count > 0 && valueTypes.Exists(t => typeKey.IsSameOrInherits(t)))
{
return EqualityStrategy.ForceEquals;
}
else if (!typeKey.IsPrimitive && referenceTypes.Count > 0 && referenceTypes.Any(t => typeKey.IsAssignableToOpenGeneric(t)))
else if (!typeKey.IsPrimitive && referenceTypes.Count > 0 && referenceTypes.Exists(t => typeKey.IsAssignableToOpenGeneric(t)))
{
return EqualityStrategy.ForceMembers;
}
else if (valueTypes.Count > 0 && valueTypes.Any(t => typeKey.IsAssignableToOpenGeneric(t)))
else if (valueTypes.Count > 0 && valueTypes.Exists(t => typeKey.IsAssignableToOpenGeneric(t)))
{
return EqualityStrategy.ForceEquals;
}
Expand Down Expand Up @@ -643,7 +642,7 @@ public TSelf ComparingByMembers(Type type)
throw new InvalidOperationException($"Cannot compare a primitive type such as {type.Name} by its members");
}

if (valueTypes.Any(t => type.IsSameOrInherits(t)))
if (valueTypes.Exists(t => type.IsSameOrInherits(t)))
{
throw new InvalidOperationException(
$"Can't compare {type.Name} by its members if it already setup to be compared by value");
Expand All @@ -669,7 +668,7 @@ public TSelf ComparingByValue(Type type)
{
Guard.ThrowIfArgumentIsNull(type);

if (referenceTypes.Any(t => type.IsSameOrInherits(t)))
if (referenceTypes.Exists(t => type.IsSameOrInherits(t)))
{
throw new InvalidOperationException(
$"Can't compare {type.Name} by value if it already setup to be compared by its members");
Expand Down
4 changes: 2 additions & 2 deletions Src/FluentAssertions/Specialized/ExceptionAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public ExceptionAssertions(IEnumerable<TException> exceptions)
return this;
}

private IEnumerable<Exception> AssertInnerExceptionExactly(Type innerException, string because = "",
private Exception[] AssertInnerExceptionExactly(Type innerException, string because = "",
params object[] becauseArgs)
{
Execute.Assertion
Expand All @@ -219,7 +219,7 @@ public ExceptionAssertions(IEnumerable<TException> exceptions)
return expectedExceptions;
}

private IEnumerable<Exception> AssertInnerExceptions(Type innerException, string because = "",
private Exception[] AssertInnerExceptions(Type innerException, string because = "",
params object[] becauseArgs)
{
Execute.Assertion
Expand Down
2 changes: 1 addition & 1 deletion Src/FluentAssertions/StringBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ internal static class StringBuilderExtensions

#if NET47 || NETSTANDARD2_0
public static StringBuilder AppendJoin<T>(this StringBuilder stringBuilder, string separator, IEnumerable<T> values) =>
stringBuilder.Append(string.Join(Environment.NewLine, values));
stringBuilder.Append(string.Join(separator, values));
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public void Reset()

internal class OneTimeEnumerable<T> : IEnumerable<T>
{
private readonly IEnumerable<T> items;
private readonly T[] items;
private int enumerations;

public OneTimeEnumerable(params T[] items) => this.items = items;
Expand All @@ -368,7 +368,7 @@ public IEnumerator<T> GetEnumerator()
throw new InvalidOperationException("OneTimeEnumerable can be enumerated one time only");
}

return items.GetEnumerator();
return items.AsEnumerable().GetEnumerator();
}
}

Expand Down