The operation results (instances of OperationResult) can be formatted using standard or custom format strings.
Standard and custom format strings are supported by some overloads of the ToString method. For example, you can supply a format string to the ToString(String) and ToString(String, IFormatProvider) methods. Standard and custom format strings are also supported by the .NET Framework composite formatting feature, which is used by some Write and WriteLine methods of the Console and StreamWriter classes, the String.Format method, and the StringBuilder.AppendFormat method. The composite format feature allows you to include the string representation of multiple data items in a single string, to specify field width, and to align values in a field.A standard OperationResult format string has a form of a single alphabetic character called the format specifier. Any OperationResult format string that is not a standard format string is interpreted as a custom OperationResult format string. This includes strings that contain any whitespace before or after the standard format specifier.
The following table describes the standard format strings and displays sample output produced by each format specifier.
Format specifier | Name | Description | |
“F” | Full (long) | Contains the indication whether the result represents a success or a failure, the error ID, the error message brief, and the count of diagnostics. | |
“g” | General (short) | Contains the indication whether the result represents a success or a failure, the error ID (if not empty), and the error message brief as necessary to describe the result. | |
“G” | General (long) | Contains the indication whether the result represents a success or a failure, the error ID (if not empty), and the error message brief and/or the count of diagnostics as necessary to describe the result. |
You can create a custom OperationResult format string, which consists of one or more custom format specifiers, to define how to format the OperationResult. A custom OperationResult format string is any format string that is not a standard OperationResult format string.
The following table describes the custom format specifiers and displays sample output produced by some of the format specifiers.
Format specifier | Name | Description | |
@ @(format) | State | Value of the named property, optionally formatted with format. | |
Dc Dc(format) | DiagnosticsCount | Value of the named property, optionally formatted with format. | |
Ds | DiagnosticsSummary | Value of the named property, optionally formatted with format. | |
K | Succeeded | Value of the named property. | |
M | ErrorMessage | Value of the named property. | |
Mb | ErrorMessageBrief | Value of the named property. | |
I | ErrorId | Value of the named property. | |
X | Exception | Value of the named property. | |
\ | Escape character | Causes the next character to be interpreted as a literal rather than as a custom format specifier. | |
'string' "string" | Literal string delimiter | Indicates that the enclosed characters should be copied to the result string unchanged. | |
; | Section separator | Defines sections with separate format. | |
Other | All other characters | The character is copied to the result string unchanged. |
The semicolon (;) is a conditional format specifier that applies different formatting to a value depending on the condition(s) it fulfills. To produce this behavior, a custom format string can contain up to two or more separated by semicolons. These sections are described in the following table.
Number of sections | Description |
1 | The format string applies to all values. |
2 | If the operation failed and the error ID is not empty, section #2 applies. Otherwise, section #1 applies. |
3 | If the operation failed and the error ID is not empty, section #3 applies. Otherwise, if the operation failed (the error ID is empty), section #2 applies. Otherwise (the operation succeeded), section #1 applies. |
4 | If the operation failed and the error ID is not empty, section #4 applies. Otherwise, if the operation failed (the error ID is empty), section #3 applies. Otherwise (the operation succeeded), if the diagnostics count is nonzero, section #2 applies. Otherwise (the operation succeeded and the diagnostics count is zero), section #1 applies. |
>= 5 | Last 4 sections are taken as if there were just 4 sections. The preceding sections are ignored. |