Skip to content

Instantly share code, notes, and snippets.

@jmaxxz
Created January 18, 2012 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmaxxz/1633719 to your computer and use it in GitHub Desktop.
Save jmaxxz/1633719 to your computer and use it in GitHub Desktop.
This rule set detects calls that are likely to cause runtime exceptions on IQueryable types. To add this rule set do: Resharper->Options->Custom Patterns ->Import
<CustomPatterns>
<Pattern Severity="ERROR" FormatAfterReplace="True" ShortenReferences="True" Language="CSHARP">
<Comment>FirstOrDefault not supported by all Queryable Types</Comment>
<ReplaceComment>Convert to supported version</ReplaceComment>
<ReplacePattern>$q$.Where($x$).FirstOrDefault()</ReplacePattern>
<SearchPattern>$q$.FirstOrDefault($x$)</SearchPattern>
<Params />
<Placeholders>
<ExpressionPlaceholder Name="q" ExpressionType="System.Linq.IQueryable" ExactType="False" />
<ArgumentPlaceholder Name="x" Minimal="1" Maximal="-1" />
</Placeholders>
</Pattern>
<Pattern Severity="ERROR" FormatAfterReplace="True" ShortenReferences="True" Language="CSHARP">
<Comment>First not supported by all Queryable Types</Comment>
<ReplaceComment>Convert to supported version</ReplaceComment>
<ReplacePattern>$q$.Where($x$).First()</ReplacePattern>
<SearchPattern>$q$.First($x$)</SearchPattern>
<Params />
<Placeholders>
<ExpressionPlaceholder Name="q" ExpressionType="System.Linq.IQueryable" ExactType="False" />
<ArgumentPlaceholder Name="x" Minimal="1" Maximal="-1" />
</Placeholders>
</Pattern>
<Pattern Severity="ERROR" FormatAfterReplace="True" ShortenReferences="True" Language="CSHARP">
<Comment>Single not supported by all Queryable Types</Comment>
<ReplaceComment>Convert to supported version</ReplaceComment>
<ReplacePattern>$q$.Where($x$).Single()</ReplacePattern>
<SearchPattern>$q$.Single($x$)</SearchPattern>
<Params />
<Placeholders>
<ExpressionPlaceholder Name="q" ExpressionType="System.Linq.IQueryable" ExactType="False" />
<ArgumentPlaceholder Name="x" Minimal="1" Maximal="-1" />
</Placeholders>
</Pattern>
<Pattern Severity="ERROR" FormatAfterReplace="True" ShortenReferences="True" Language="CSHARP">
<Comment>SingleOrDefault not supported by all Queryable Types</Comment>
<ReplaceComment>Convert to supported version</ReplaceComment>
<ReplacePattern>$q$.Where($x$).SingleOrDefault()</ReplacePattern>
<SearchPattern>$q$.SingleOrDefault($x$)</SearchPattern>
<Params />
<Placeholders>
<ExpressionPlaceholder Name="q" ExpressionType="System.Linq.IQueryable" ExactType="False" />
<ArgumentPlaceholder Name="x" Minimal="1" Maximal="-1" />
</Placeholders>
</Pattern>
<Pattern Severity="ERROR" FormatAfterReplace="True" ShortenReferences="True" Language="CSHARP">
<Comment>Any not supported by all Queryable Types</Comment>
<ReplaceComment>Convert to supported version</ReplaceComment>
<ReplacePattern>$q$.Where($x$).Any()</ReplacePattern>
<SearchPattern>$q$.Any($x$)</SearchPattern>
<Params />
<Placeholders>
<ExpressionPlaceholder Name="q" ExpressionType="System.Linq.IQueryable" ExactType="False" />
<ArgumentPlaceholder Name="x" Minimal="1" Maximal="-1" />
</Placeholders>
</Pattern>
<Pattern Severity="ERROR" FormatAfterReplace="True" ShortenReferences="True" Language="CSHARP">
<Comment>All not supported by all Queryable Types</Comment>
<ReplaceComment>Convert to supported version</ReplaceComment>
<ReplacePattern>$q$.Where($x$).All()</ReplacePattern>
<SearchPattern>$q$.All($x$)</SearchPattern>
<Params />
<Placeholders>
<ExpressionPlaceholder Name="q" ExpressionType="System.Linq.IQueryable" ExactType="False" />
<ArgumentPlaceholder Name="x" Minimal="1" Maximal="-1" />
</Placeholders>
</Pattern>
</CustomPatterns>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment