Code Issues hints for types and members
Here are the suggestions (hints) code issues which might improve the readability, clarity and performance of your source code.
Initializer can be used
Cause:
Object initializers allow multiple property values to be set within a single object instance creation operation. They are used in conjunction with existing object constructors. Object initializers provide a simplified syntax for specifying initial values for one or more properties of an object. Using an object initializer may improve code readability.
Sample:
How to fix:
- Apply the Convert to Initializer refactoring:
Partial class has only single part
Cause:
A class, structure or interface can be marked as partial to allow its definition to be split between several files. If a type is marked as partial and has only a single part, there is no need to mark it partial. Removing the partial keyword may increase code clarity.
Sample:
How to fix:
- Remove the ‘partial’ keyword:
Property can be auto-implemented
Cause:
If a property uses a simple backing store field and have the corresponding accessors to return the value of the field, and set the value to the field, this property can be simplified to an automatically implemented property. This usual syntax for declaring a read/write property includes a large number of lines of code for a relatively simple task. Converting such a property into an auto-implemented property may increase code readability a lot.
Sample:
How to fix:
- Apply the Convert to Auto-implemented Property refactoring:
Redundant delegate creation
Cause:
In some cases, specifying the delegate type explicitly is redundant. For example, it is redundant when you subscribe to an event, because the compiler will infer the type of the delegate automatically from the event handler creation code.
Sample:
How to fix:
- Apply the Remove Redundant Delegate Creation refactoring:
Redundant sealed modifier
Cause:
If a member marked as ‘sealed’ is located inside the class which is also marked sealed, then there’s no need to mark a member as sealed, because the use of the sealed keyword on a class prevents the class from inheriting functionality for all its members.
Sample:
How to fix:
- Remove the ‘sealed’ keyword:
Type can be moved to separate file
Cause:
It is recommended to have a single class per source file. If a file contains several neighborhood classes, and a particular class can be moved to its own file (e.g., a type name differs from the file name), a hint is shown indicating that the class can be moved.
Sample:
How to fix:
- Apply the Move Type to File refactoring to each class:
Type name does not correspond to file name
Cause:
It is also recommended to have a class name that corresponds to the file name, where the class resides. If a class name does not correspond to the file name, the hint is shown suggesting you to rename a file or a class to a single name.
Sample:
How to fix:
- Apply the Rename File to Match Type refactoring:
- Apply the Rename Type to Match File refactoring:
—– Products: CodeRush Pro Versions: 12.1 and up VS IDEs: 2008 and up Updated: Sep/28/2012 ID: C192