Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
pshao25 committed Jul 27, 2023
1 parent 6056a2e commit ece6ad4
Showing 1 changed file with 5 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,16 @@ public override void Analyze(ISymbolAnalysisContext context)
AnalyzeCore(context);
}

protected class ParameterEquivalenceComparerOptionalIgnore : ParameterEquivalenceComparer
{
public static new ParameterEquivalenceComparerOptionalIgnore Default { get; } = new ParameterEquivalenceComparerOptionalIgnore();

public override bool Equals(IParameterSymbol x, IParameterSymbol y)
{
return x.Name.Equals(y.Name) && TypeSymbolEquals(x.Type, y.Type);
}
}

protected class ParameterEquivalenceComparer : IEqualityComparer<IParameterSymbol>, IEqualityComparer<ITypeParameterSymbol>
{
public static ParameterEquivalenceComparer Default { get; } = new ParameterEquivalenceComparer();

public virtual bool Equals(IParameterSymbol x, IParameterSymbol y)
public bool Equals(IParameterSymbol x, IParameterSymbol y)
{
return x.Name.Equals(y.Name) && TypeSymbolEquals(x.Type, y.Type) && x.IsOptional == y.IsOptional;
}

protected virtual bool TypeSymbolEquals(ITypeSymbol x, ITypeSymbol y)
private bool TypeSymbolEquals(ITypeSymbol x, ITypeSymbol y)
{
switch (x)
{
Expand Down Expand Up @@ -96,19 +86,19 @@ protected static IMethodSymbol FindMethod(IEnumerable<IMethodSymbol> methodSymbo
parameters.SequenceEqual(symbol.Parameters, ParameterEquivalenceComparer.Default));
}

protected static IMethodSymbol FindMethod(IEnumerable<IMethodSymbol> methodSymbols, ImmutableArray<ITypeParameterSymbol> genericParameters, ImmutableArray<IParameterSymbol> parameters, Func<IParameterSymbol, bool> lastParameter, ParameterEquivalenceComparer comparer = null)
protected static IMethodSymbol FindMethod(IEnumerable<IMethodSymbol> methodSymbols, ImmutableArray<ITypeParameterSymbol> genericParameters, ImmutableArray<IParameterSymbol> parameters, Func<IParameterSymbol, bool> lastParameter)
{

return methodSymbols.SingleOrDefault(symbol =>
{
if (!symbol.Parameters.Any() || !genericParameters.SequenceEqual(symbol.TypeParameters, comparer ?? ParameterEquivalenceComparer.Default))
if (!symbol.Parameters.Any() || !genericParameters.SequenceEqual(symbol.TypeParameters, ParameterEquivalenceComparer.Default))
{
return false;
}

var allButLast = symbol.Parameters.RemoveAt(symbol.Parameters.Length - 1);

return allButLast.SequenceEqual(parameters, comparer ?? ParameterEquivalenceComparer.Default) && lastParameter(symbol.Parameters.Last());
return allButLast.SequenceEqual(parameters, ParameterEquivalenceComparer.Default) && lastParameter(symbol.Parameters.Last());
});
}

Expand Down

0 comments on commit ece6ad4

Please sign in to comment.