C#

C#

By DeepSource

Empty default label without a comment is redundant CS-R1022
Anti-pattern

The 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.

Consider having 1 public class per namespace CS-R1035
Anti-pattern

Having 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.

Explicit trap of NullReferenceException CS-R1009
Anti-pattern

Explicit 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.

Consider declaring only 1 namespace per file CS-R1034
Anti-pattern

Namespaces 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.

Getters must not throw exceptions CS-R1038
Anti-pattern

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.