Class ValueMasker
Masks string values. A masker is built once from a MaskingSpecification, is stateless and can be shared by concurrent requests.
public abstract class ValueMasker
- Inheritance
-
ValueMasker
- Inherited Members
Remarks
A masker never returns a value in clear by accident: a value that does not have the expected format, an error while masking, or a mask that would hide nothing all end in a full mask.
Constructors
ValueMasker(char)
Initializes a new instance of the ValueMasker class.
protected ValueMasker(char maskCharacter)
Parameters
maskCharactercharThe character that replaces each masked character.
Properties
MaskCharacter
Gets the character that replaces each masked character.
protected char MaskCharacter { get; }
Property Value
Methods
Create(MaskingSpecification)
Creates the masker described by a specification.
public static ValueMasker Create(MaskingSpecification specification)
Parameters
specificationMaskingSpecificationThe masking specification.
Returns
- ValueMasker
The masker.
Exceptions
- ArgumentException
The specification is not valid.
HasMaskedForm(string)
Determines whether a value has the form of a masked value: it holds the masking character, and masking it again leaves it unchanged or masks it fully.
public virtual bool HasMaskedForm(string value)
Parameters
valuestringThe value.
Returns
Remarks
A mask, even one edited in its visible parts, is unchanged when masked again. A real value that holds the masking character is changed, unless the format does not accept it.
Mask(string?)
Masks a value.
public string? Mask(string? value)
Parameters
valuestringThe value to mask.
Returns
MaskCore(string)
Masks a non-empty value.
protected abstract string MaskCore(string value)
Parameters
Returns
- string
The masked value.
MaskFully(string)
Masks every character of a value, separators included. Used as well whenever masking fails or hides nothing.
protected virtual string MaskFully(string value)
Parameters
valuestringThe value to mask.
Returns
- string
One masking character per character of the value.