default
label without a comment is redundant CS-R1022The default
case in a switch
is executed when none of the provided cases match. An empty default
case without a user comment is redundant. Either add a user comment to indicate to the reader and the analyzer that all the possible cases have been covered, or, consider throwing a NotImplementedException
to indicate that some cases are yet to be handled.
public
class per namespace CS-R1035Having more than 1 public class per namespace increases the complexity and affects the overall code readability and navigation. It is therefore recommended that you have a single public
class per namespace
.
NullReferenceException
CS-R1009Explicit trapping of NullReferenceException
is usually considered a bad practice. It usually means that your application has come across a null
reference in an unexpected manner which you're trying to suppress by explicitly trapping through a catch
block rather than finding the root cause. Since this was unexpected, it is probably not safe for your application to continue with the execution.
namespace
per file CS-R1034Namespaces are used to organize classes and control the scope of class and method names in larger projects. Having more than 1 namespace per file increases the complexity and affects the overall code readability and navigation. It is therefore recommended that you have a single namespace per file.
While it is acceptable for setters to throw exceptions, getters are simply expected to return a value. Throwing any exception is considered an antipattern and is not a recommended practice. It is recommended that you refactor your code accordingly.