Quantcast
Channel: YouTrackReSharper (RSRP) - Bug and Issue Tracker
Viewing all articles
Browse latest Browse all 106942

RSRP-274851: Non-redunant call to Cast LINQ method shown as redundant

$
0
0
Reporter Arsène von Wyss (avonwyss) Arsène von Wyss (avonwyss)
Created Aug 11, 2011 9:44:25 PM
Updated Dec 28, 2011 12:18:31 AM
Resolved Dec 27, 2011 5:40:11 PM
Priority Normal
Type Bug
Fix versions Next
State Fixed
Assignee Evgeny Pasynkov (pasynkov)
Subsystem No subsystem
Affected versions No Affected versions
Fixed in build 6.5.1.1441
Whenever you extend a non-generic collection and want to add a generic enumerator, you'll implement code such as this:
public class ElementCollection: ConfigurationElementCollection, IEnumerable<ElementType> {
	public new IEnumerator<ElementType> GetEnumerator() {
		return this.Cast<ElementType>().GetEnumerator();
	}
}

One such example is when inheriting from ConfigurationElementCollection, which are collections with a known element type, but not implementing the generic IEnumerable interface.

R# suggests that "Cast<ElementType>()" is redundant, and the proposed fix is to remove the redundant code. Doing this however changes the code so that it will cause a stack overflow at runtime due to the unwanted recursion.

Viewing all articles
Browse latest Browse all 106942

Trending Articles