Class PatternStringConverter
- Namespace
- NuvTools.AspNetCore.Blazor.MudBlazor.Converters
- Assembly
- NuvTools.AspNetCore.Blazor.MudBlazor.dll
Pattern-based string converter for MudBlazor input components.
public class PatternStringConverter : DeferredConverter<string?, string?>, IReversibleConverter<string?, string?>, IConverter<string?, string?>
- Inheritance
-
PatternStringConverter
- Implements
- Inherited Members
-
DeferredConverter<string, string>.Convert(string)DeferredConverter<string, string>.ConvertBack(string)
Examples
// Phone number: (NN) NNNNN-NNNN
var phoneConverter = new PatternStringConverter("(NN) NNNNN-NNNN");
// License plate: LLL-NANN
var plateConverter = new PatternStringConverter("LLL-NANN");
Remarks
Pattern characters:
A- Alphanumeric (letters and digits)N- Numeric (digits only)L- Letter (letters only)
Any other character in the pattern is treated as a literal separator.
Constructors
PatternStringConverter(string, bool)
Initializes a new instance of the PatternStringConverter class.
public PatternStringConverter(string pattern, bool toUpperCase = true)
Parameters
patternstringThe pattern string defining the format. Use A for alphanumeric, N for numeric, L for letter.
toUpperCaseboolIf true, converts input to uppercase. Default is true.
Exceptions
- ArgumentException
Thrown when pattern is null or whitespace.
Methods
Format(string?)
Formats the specified value according to the pattern.
public string? Format(string? value)
Parameters
valuestringThe raw value to format.
Returns
- string
The formatted value, or null if the input is empty.