Here is a part of my new code replacing the old and deprecated old-school one.
Let's get to business right away:
I document everything with Documentation comments, which are proving very useful so far.
I present you my new tiny class called
Validity, of which goal is to indicate if something is valid or not, and if not, then there should be specified a reason for it.
Note: I actually tried to use struct instead, but as it appears, parameterless constructors are from C# >= 10 or something like that there.
There shall be absolutely no problem for you to review as I documented, well, everything. I welcome all of your tips to make it perfect as in more effective or better to use, safer, or whatsoever...
/* I have a bunch of localized strings to my language. */
private const string INPUT_EMPTY = "Input is empty";
/// <summary>
/// <para>
/// Generic storage object for valid bools and various invalidity reasons.
/// </para>
/// </summary>
public class Validity
{
/// <summary>
/// <para>
/// This indicates if something is valid or not.
/// </para>
/// </summary>
public bool IsValid { get; set; }
/// <summary>
/// <para>
/// If something is invalid, this indicates a reason for it.
/// </para>
/// </summary>
public string ReasonForInvalid { get; set; }
/// <summary>
/// <para>
/// The default parameterless constructor assumes:
/// <code>
/// IsValid == true
/// </code>
/// and expects no reason for it whatsoever.
/// </para>
/// </summary>
public Validity()
{
IsValid = true;
ReasonForInvalid = "";
}
/// <summary>
/// <para>
/// The second constructor assumes:
/// <code>
/// IsValid == false
/// </code>
/// and expects a reason for being invalid.
/// </para>
/// </summary>
public Validity(in string aReasonForInvalid)
{
IsValid = false;
ReasonForInvalid = aReasonForInvalid;
}
}
/* Just to try it out, and declare something! :) */
Validity InputValidity = new Validity(INPUT_EMPTY);