📉ConsoleBase - NKS0006

Use ReadLine() from InputTools

This analyzer provides the following strings:

ContextString

Error List

Caller uses Console.ReadLine instead of ReadLine()

Suggestion Box

Use ReadLine() instead of Console.ReadLine

Description

ReadLine() provided by the input helper from Nitrocid allows you to seamlessly read a user input with settings provided by Terminaux.

Extended Description

This code analyzer detects the usage of ReadLine from the standard Console class found in the System namespace. While this function brings some of the awesome features, such as the history and the positioning, they are limited in terms of flexibility.

Historically, it had problems with Mono on Linux not playing nice with these features, causing the console to register an incorrect character to the buffer, messing things up in the process. This was one of the outstanding issues that we had to deal with during the development of 0.0.16.0 in 2021.

The ReadLine() provided by Nitrocid KS is a wrapper to Terminaux's console input reader feature, except that the settings are managed by Nitrocid KS and that their histories are saved once the kernel shuts down, further allowing flexibility.

Analysis Comparison

To get a brief insight about how this analyzer works, compare the two code blocks shown to you below:

Before the fix

Somewhere in your mod code...
public static void MyFunction() =>
    string input = Console.ReadLine();

After the fix

Somewhere in your mod code...
public static void MyFunction() =>
    string input = InputTools.ReadLine();

Suppression

You can suppress this suggestion 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 this property use the recommended abovementioned method.

Last updated