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

RSRP-289037: Suggested code change to avoid a NullReferenceException has faulty logic

$
0
0
Reporter guest (guest2) guest (guest2)
Created Mar 5, 2012 8:54:55 PM
Updated Mar 5, 2012 8:59:35 PM
Priority Normal
Type Bug
Fix versions No Fix versions
State Submitted
Assignee Unassigned
Subsystem No subsystem
Affected versions No Affected versions
Fixed in build No Fixed in build
Build 6.1.1000.82; Visual Studio 10.0.40219.1

ReSharper converted this:

cvs.View.Filter =
c =>
string.IsNullOrWhiteSpace(filter.Text) ||
(typeof(string) == type && (c as string).StartsWith(filter.Text, StringComparison.InvariantCultureIgnoreCase)) ||
(property != null && property.GetValue(c, null).ToString().StartsWith(filter.Text, StringComparison.InvariantCultureIgnoreCase));


into [BAD]
cvs.View.Filter =
c =>
{
var s = c as string;
return s != null && (string.IsNullOrWhiteSpace(filter.Text) ||
(typeof(string) == type && s.StartsWith(filter.Text, StringComparison.InvariantCultureIgnoreCase)) ||
(property != null && property.GetValue(c, null).ToString().StartsWith(filter.Text, StringComparison.InvariantCultureIgnoreCase)));
};

An improvement that works looks like this:
cvs.View.Filter =
c =>
{
var s = c as string;
      return string.IsNullOrWhiteSpace(filter.Text) 
||
(s != null &&
(typeof(string) == type && s.StartsWith(filter.Text, StringComparison.InvariantCultureIgnoreCase)) ||
(property != null && property.GetValue(c, null).ToString().StartsWith(filter.Text, StringComparison.InvariantCultureIgnoreCase)));
};

The failure broke a CollectionViewSource in a very visible way.

Viewing all articles
Browse latest Browse all 106942

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>