You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add analyzer rule for ArgumentException.ThrowIfContainsDuplicates #728
NetEvolve.Arguments provides ArgumentException.ThrowIfContainsDuplicates(IEnumerable<T>, IEqualityComparer<T>?) to validate that a collection contains no duplicate elements. NetEvolve.Arguments.Analyser does not currently have a rule that detects the manual equivalent of this check.
Problem
The manual implementation of a duplicate check is a multi-statement algorithm rather than a single expression, e.g.:
Because this spans a loop/multiple statements (not a single if (condition) throw ... expression) and has many equivalent formulations, it doesn't fit the single-expression pattern-matching approach used by the current rules and needs a dedicated design (e.g. matching on a HashSet<T>-based loop shape, or restricting scope to specific LINQ-based idioms).
Proposed solution
Design and implement a new rule (next available ID) that recognizes at least the most common LINQ-based shape (e.g. arg.Distinct().Count() != arg.Count() / .GroupBy(...).Any(g => g.Count() > 1)), with a code fix rewriting to ArgumentException.ThrowIfContainsDuplicates(arg). If reliable detection isn't feasible, document that decision and close as won't-fix.
Activity