CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: XML

ReSharper 5.0: Structural Search and Replace

570 Views
Copy Code Show/Hide Line Numbers
<CustomPatterns>
  <Pattern Severity="SUGGESTION">
    <Comment>Use method Any()</Comment>
    <ReplacePattern>$seq$.Any()</ReplacePattern>
    <SearchPattern><![CDATA[$seq$.Count() > 0]]></SearchPattern>
    <Params />
    <Placeholders>
      <ExpressionPlaceholder Name="seq" ExpressionType="System.Collections.IEnumerable" ExactType="False" />
    </Placeholders>
  </Pattern>
  <Pattern Severity="SUGGESTION">
    <Comment>Replace with ternary operator</Comment>
    <ReplacePattern>$x$ = $condition$ ? $expr1$ : $expr2$;</ReplacePattern>
    <SearchPattern><![CDATA[if ($condition$)
  { $x$ = $expr1$; }
else
  { $x$ = $expr2$; }]]></SearchPattern>
    <Params />
    <Placeholders>
      <ExpressionPlaceholder Name="condition" ExpressionType="System.Boolean" ExactType="False" />
      <IdentifierPlaceholder Name="x" Type="" ExactType="False" RegEx="" CaseSensitive="True" />
      <ExpressionPlaceholder Name="expr1" ExpressionType="" ExactType="True" />
      <ExpressionPlaceholder Name="expr2" ExpressionType="" ExactType="True" />
    </Placeholders>
  </Pattern>
</CustomPatterns>
by Jon Erickson
  April 07, 2010 @ 8:51am
Tags:
Description:
http://blogs.jetbrains.com/dotnet/2010/04/introducing-resharper-50-structural-search-and-replace/#comment-312022

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate