CleanCode
CleanCode copied to clipboard
Too many chained references - Ignore when using LINQ
I think the inspection for "Too many chained references " should ignore anything in the LINQ namespace.
Hmm. This is an interesting one, because it might be that you're using a custom SelectMany
extension method from another namespace, or even a custom operator, DistinctIgnoringCase
or something.
I wonder if there's a good way to generalise this? Perhaps extend the check for "fluent" interfaces, where it doesn't count methods that return the same type that's passed in, e.g. IEnumerable<T>
. It would need to ignore the actual type of T
, for things like Select((string s) => s.Length
, which would start as IEnumerable<string>
and return IEnumerable<int>
.
That would mean the chained LINQ methods are ignored, but if you have too many chained references after standard LINQ, they'd be marked as smelly code.
How does that sound?
This may require a few special cases. My suggestion would be to ignore or increase the allowable threshold when
- Using extension methods where both the first input argument and return type implement
IEnumerable<T>.
- Using extension methods where both the first input argument and return type are the same type.