Skip to content
| Marketplace
Sign in
Visual Studio>Tools>Code Analysis Rule Collection (Common)
Code Analysis Rule Collection (Common)

Code Analysis Rule Collection (Common)

Peter Juhasz

|
1,870 installs
| (2) | Free
Contains a set of diagnostics, code fixes and refactorings built on the Microsoft .NET Compiler Platform "Roslyn".
Download

Contains a set of common diagnostics, code fixes and refactorings built on the Microsoft .NET Compiler Platform "Roslyn".

Requirements:

  • Roslyn End User Preview

Content

Analysis:

  • Check parameter name in ArgumentExceptions
  • Parameter is not checked for null before use
  • Local variable(s) can be made constant
  • Check object to lock on
  • Check property name in property change and changing notifications
  • Unnecessary comparison to a boolean constant (boolean == true)
  • Empty string literal ""
  • Type name does not meet naming guidelines (excluding types marked with CompilerGenerated or StructLayout attribute)
  • Statement has no effect (e.g.: textWriter.Write("");)

Fixes:

  • Check parameter for null (or empty string) before use
    • Throw exception conditionally
    • Using Code Contracts
  • Make variable constant
  • Remove unnecessary comparison to boolean
  • Introduce lock object, when the current one is not recommended
    • Introduce instance-level object
    • Introduce static object
  • Use String.Empty instead of ""
  • Fix type name, if does not meet naming guidelines
  • Remove statement, which has no effect

Refactorings:

  • Implement property change notification (and property changing notification)
    • The regualar way
    • Using compiler services
  • Introduce and assign from constuctor parameter
    • Protected read-only field
    • Public property
  • Check parameter for
    • null (throw exception, code contracts)
    • empty string (string)
    • negative number (int)
    • later than today (DateTime)
    • IntPtr.Zero (IntPtr)
  • Generate singleton property
    • With initial value
    • With lazy loading
    • With lazy loading using System.Lazy<T>
    • With locking and lazy loading
    • With Interlocked.CompareExchange and lazy loading
  • Expand property declaration
  • Collapse property to auto-property
  • Expand event declaration
  • Promote local contant to field (+ static read-only)
  • Promote local to field (+ with initialization)
  • Use explicit typing, resolve 'var'
  • Convert if statement to conditional expression (assignments)
  • Convert constant to read-only field
  • Remove unnecessary braces

Demo

Check parameter for null before use

Parameter name validation in argument exceptions

Make variable constant

Property name validation in property change and changing notifications

Source Code

Source code will be available on CodePlex soon.

Change Log

0.1.17

  • Promote local to field (+ with initialization)
  • Promote local constant to field (static read-only)

0.1.16

  • Implementing property change notification supports implementing property changing notification as well
  • Refactor: Convert constant to read-only field

0.1.15

  • Fix: Check parameter for null or empty string
  • Refactoring: Check parameter for null, empty string, negative number, later than today, IntPtr.Zero
  • Collapse to auto-property supports initializer expression
  • Bug fix: Collapse to auto-property removes only the corresponding variable from a field declaration (it may contain multiple declarations).

0.1.14

  • Refactoring: Promote local constant(s in declaration) to field(s)
  • Analysis: Unnecessary comparison to a boolean constant (e.g.: boolean == true)
  • Fix: Remove unnecessary comparison to boolean

0.1.13

  • Analysis: Added 'base' to 'do not lock on current instance'
  • Fix: Introduce lock object when the current one is not recommended
  • Name conflicts are now resolved when introducing new members
  • Bug fixes

0.1.12

  • Refactoring: Introduce read-only field or property from constructor parameter
  • Analysis: Do not lock on null, strings, typeof (public types) and 'this' objects
  • Bug fixes
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft