Table of Contents

Class BaseMask

Namespace
MudBlazor
Assembly
MudBlazor.dll

A base class for designing input masks for the MudMask, MudTextField<T>, and MudPicker<T> components.

public abstract class BaseMask : IMask
Inheritance
BaseMask
Implements
Derived
Inherited Members
Extension Methods

Constructors

BaseMask()

protected BaseMask()

Fields

_delimiters

protected HashSet<char> _delimiters

Field Value

HashSet<char>

_initialized

protected bool _initialized

Field Value

bool

_maskChars

protected MaskChar[] _maskChars

Field Value

MaskChar[]

_maskDict

protected Dictionary<char, MaskChar> _maskDict

Field Value

Dictionary<char, MaskChar>

Properties

AllowOnlyDelimiters

Allows showing text which consists only of delimiter characters.

public bool AllowOnlyDelimiters { get; set; }

Property Value

bool

CaretPos

The current cursor position.

public int CaretPos { get; set; }

Property Value

int

Mask

The characters which define the accepted input.

public string Mask { get; protected set; }

Property Value

string

MaskChars

The list of mask characters and their meanings.

public MaskChar[] MaskChars { get; set; }

Property Value

MaskChar[]

Remarks

Defaults to a for letters, 0 for digits, and * for letters or digits.

Selection

The start and end range of selected characters.

public (int, int)? Selection { get; set; }

Property Value

(int, int)?

Text

The current text displayed in the input, including delimiter and placeholder characters.

public string Text { get; protected set; }

Property Value

string

Methods

Backspace()

Triggers a backspace at the current cursor position.

public abstract void Backspace()

Remarks

Has the same effect as pressing the Backspace key.

Clear()

Clears the text and selection.

public void Clear()

ConsolidateCaret(string, int)

Adjusts the cursor position to be within the text.

protected static int ConsolidateCaret(string text, int caretPos)

Parameters

text string
caretPos int

Returns

int

Remarks

If Text is empty, the position becomes 0. If the position was beyond the length of Text, the position is adjusted to the end. Otherwise, no change is made.

ConsolidateSelection()

Adjusts the selection to be within the text.

protected void ConsolidateSelection()

Remarks

If the selection has zero length, the selection is deleted. If the selection start is less than 0, the start becomes 0. If the end is longer than the length of Text, the end becomes the text length.

Delete()

Triggers a delete at the current cursor position.

public abstract void Delete()

Remarks

Has the same effect as pressing the Delete key.

DeleteSelection(bool)

Deletes the selected characters.

protected abstract void DeleteSelection(bool align)

Parameters

align bool

When true, the text to the right of the selection will be shifted to the left.

GetCleanText()

The current text in the input, excluding delimiter or placeholder characters.

public virtual string GetCleanText()

Returns

string

Init()

Initialize all internal data structures. Can be called multiple times, will initialize only once. To re-initialize set _initialized to false.

protected void Init()

InitInternals()

Initializes this mask's characters and delimiters.

protected virtual void InitInternals()

Insert(string)

Inserts text at the current cursor position.

public abstract void Insert(string input)

Parameters

input string

The characters to insert.

IsDelimiter(char)

Gets whether the specified character is a mask character.

protected virtual bool IsDelimiter(char maskChar)

Parameters

maskChar char

The character to examine.

Returns

bool

When true, the character is a delimiter.

Refresh()

Reapplies parameters after they change, while preserving Text, CaretPos, and Selection.

protected virtual void Refresh()

SetText(string)

Overwrites the text without losing the cursor position.

public void SetText(string text)

Parameters

text string

The text to set.

ToString()

Gets the current input including markers for caret and selection.

public override string ToString()

Returns

string

Remarks

This method is used frequently by unit tests.

UpdateFrom(IMask)

Copies the mask and mask characters from the specified mask.

public virtual void UpdateFrom(IMask o)

Parameters

o IMask

UpdateText(string)

Overwrites the text and updates the cursor position.

protected virtual void UpdateText(string text)

Parameters

text string

The text to set.