📉ConsoleBase - NKS0002
Use ConsoleWrapper instead of Console
This analyzer provides the following strings:
Context | String |
---|---|
Error List | Caller uses |
Suggestion Box | Use |
Description |
|
Extended Description
This code analyzer detects the usage of the standard Console
class found in the System
namespace. However, this class is a sealed class, so it's rendered inextensible, causing you to have to make its abstraction class to wrap its functions if you want to add extra code, like checking for VT sequences.
Fortunately, Nitrocid KS has its own console wrapper, ConsoleWrapper
, that makes use of the current local console driver that contains the necessary checks, like checking the console for its fullness (positioning and any other functions other than plain writing).
So, if you want to use the Console
class, you must replace these calls with ConsoleWrapper
to take advantage of the local console drivers.
Furthermore, some of the wrapper functions are used by the much powerful console writers, like TextWriterColor.Write()
, that include sanity checks before actually doing the job.
Analysis Comparison
To get a brief insight about how this analyzer works, compare the two code blocks shown to you below:
Before the fix
After the fix
Suppression
You can suppress this warning by including it in the appropriate place, whichever is convenient.
For more information about how to suppress any warning issued by the Nitrocid analyzer, visit the below page:
Recommendation
We recommend that every caller which use the Console
class use the recommended abovementioned class.
Last updated