Property Pattern
- Namespace
- Bonsai.Expressions
- Assembly
- Bonsai.Core.dll
Pattern
Gets or sets the parse pattern to match, including data type format specifiers.
[TypeConverter(typeof(ParseBuilder.PatternConverter))]
public string Pattern { get; set; }
Property Value
Remarks
The parse pattern may contain zero or more placeholder characters. Each placeholder is always preceded by the character %
, and must specify one of the allowed data type format specifiers (see table below). For each placeholder in the pattern, the Parse
method of the corresponding data type will be called to convert the matched string to an equivalent instance of that type.
Note
Some placeholder conversions will account for white space characters surrounding the input, e.g. the parse pattern %i,%i
will work the same for 1,2
or 1, 2
.
Warning
All parse conversions are done using the invariant culture. Specifying culture-specific conversions is not currently supported. There is also no support for implicit numeric conversions, e.g. attempting to parse 5.0
using %i
will throw an error.
If the parse pattern is null
or empty, the operator will simply return the raw input value. If a non-empty parse pattern is provided, but no placeholder characters are specified, the result type will be of type Unit. Otherwise, the output type will be a tuple of the types corresponding to each of the placeholder characters, in order of their appearance in the parse pattern.
Pattern | Description |
---|---|
%B |
Match an unsigned 8-bit integer (byte). |
%h |
Match a signed 16-bit integer (short). |
%H |
Match an unsigned 16-bit integer (ushort). |
%i |
Match a signed 32-bit integer (int). |
%I |
Match an unsigned 32-bit integer (uint). |
%l |
Match a signed 64-bit integer (long). |
%L |
Match an unsigned 64-bit integer (ulong). |
%f |
Match a single-precision floating-point number (float). |
%d |
Match a double-precision floating-point number (double). |
%b |
Match a Boolean (true or false ) value (bool). |
%c |
Match a single character as a UTF-16 code unit (char). |
%s |
Match a text fragment using UTF-16 encoding (string). |
%t |
Match a timestamp measured relative to UTC time (DateTimeOffset). |
%T |
Match a time interval (TimeSpan). |
Warning
The parse pattern is a regular expression string and certain characters are reserved as special tokens, such as parentheses. It is possible to use these special characters by prefixing them with a backslash (e.g. \(
for a left parentheses).