Introduction
Avalanche.StatusCodes.System.dll contains mscorlib.txt statuscodes, [git], [www].
Add package reference to .csproj.
<PropertyGroup>
<RestoreAdditionalProjectSources>https://avalanche.fi/Avalanche.Core/nupkg/index.json</RestoreAdditionalProjectSources>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Avalanche.StatusCodes.System"/>
</ItemGroup>
SystemMessages.Messages contains statuscodes and display texts that are automatically scraped from MIT-licensed mscorlib.dll (Multi-language Standard Common Object Runtime Library).
Each key from mscorlib.txt is assigned with a message description.
IMessageDescription messageDescription = SystemMessages.Messages.Keys["mscorlib.Arg_ParamName_Name"];
Each key is assigned with a permanent code. Codes have facility value 0x23450000 for successful codes and 0xA3450000 for errors.
IMessageDescription messageDescription = SystemMessages.Messages.Codes[unchecked((int)0xA34500CB)];
int code = messageDescription.Code!.Value;
Most descriptions are associated with a HResult code.
int? hresult = SystemMessages.Messages.Keys["mscorlib.Arg_ParamName_Name"].HResult;
Most descriptions have an associated exception type.
Type? error = SystemMessages.Messages.Keys["mscorlib.Arg_ParamName_Name"].Exception as Type;
Descriptions have a template text.
// Get template text
ITemplateText templateText = SystemMessages.Messages.Keys["mscorlib.Arg_ParamName_Name"].Template;
// Print template text
WriteLine(templateText); // "Parameter name: {0}"
And each key is organized by group and is assigned to a class and a field.
// Argumentize file not found
IMessage filenotfound = SystemMessages.IO.FileNotFoundFileName.New("file.txt");
// Print template text
WriteLine(filenotfound); // "Could not find file 'file.txt'."
Note however that there is a heuristic algorithm that chooses class and field name, and is prone to errors, which may be corrected later. Therefore, it is recommended to not use field reference, but instead refer by Key or by Code.
IMessageDescription messageDescription1 = SystemMessages.Messages.Keys["mscorlib.Arg_ParamName_Name"];
IMessageDescription messageDescription2 = SystemMessages.Messages.Codes[unchecked((int)0xA34500CB)];
Full example
using Avalanche.Message;
using Avalanche.StatusCode;
using Avalanche.Template;
using static System.Console;
class system_index
{
public static void Run()
{
{
// <10>
IMessageDescription messageDescription = SystemMessages.Messages.Keys["mscorlib.Arg_ParamName_Name"];
// </10>
}
{
// <11>
IMessageDescription messageDescription = SystemMessages.Messages.Codes[unchecked((int)0xA34500CB)];
int code = messageDescription.Code!.Value;
// </11>
}
{
// <12>
int? hresult = SystemMessages.Messages.Keys["mscorlib.Arg_ParamName_Name"].HResult;
// </12>
}
{
// <13>
Type? error = SystemMessages.Messages.Keys["mscorlib.Arg_ParamName_Name"].Exception as Type;
// </13>
}
{
// <14>
// Get template text
ITemplateText templateText = SystemMessages.Messages.Keys["mscorlib.Arg_ParamName_Name"].Template;
// Print template text
WriteLine(templateText); // "Parameter name: {0}"
// </14>
}
{
// <15>
// Argumentize file not found
IMessage filenotfound = SystemMessages.IO.FileNotFoundFileName.New("file.txt");
// Print template text
WriteLine(filenotfound); // "Could not find file 'file.txt'."
// </15>
}
{
// <16>
IMessageDescription messageDescription1 = SystemMessages.Messages.Keys["mscorlib.Arg_ParamName_Name"];
IMessageDescription messageDescription2 = SystemMessages.Messages.Codes[unchecked((int)0xA34500CB)];
// </16>
}
}
}
Table
SystemMessages.Instance contains following message descriptions:
Field Name | Description |
---|---|
AccessControl | System.Security.AccessControl.* |
Aggregate | System.AggregateException |
AppDomain | System.AppDomain.* |
Argument | System.ArgumentException |
ArgumentNull | System.ArgumentNullException |
ArgumentOutOfRange | System.ArgumentOutOfRangeException |
Arithmetic | |
Array | |
Assembly | |
BadImageFormat | System.BadImageFormatException |
CodeContract | |
CodePage | |
Collections | System.Collections.* |
CompilerService | System.Runtime.CompilerServices.* |
Cryptography | System.Security.Cryptography.* |
Culture | System.Globalization.Culture* |
Diagnostics | System.Diagnostics.* |
EventSource | System.Diagnostics.Tracing.EventSourceException |
ExecutionEngine | |
Format | System.FormatException |
HostProtection | System.Security.HostProtectionException |
IO | System.IO.* |
IndexOutOfRange | System.IndexOutOfRangeException |
InteropService | System.Runtime.InteropServices.* |
InvalidCast | System.InvalidCastException |
InvalidOperation | System.InvalidOperationException |
IsolatedStorage | System.IO.IsolatedStorage.* |
Lazy | System.Threading.Lazy |
Marshaler | |
Memory | |
Miscellaneous | |
NotImplemented | System.NotImplementedException |
NotSupported | System.NotSupportedException |
ObjectDisposed | System.ObjectDisposedException |
OperationCanceled | System.OperationCanceledException |
Overflow | System.OverflowException |
Platform | |
Policy | System.Security.Policy.* |
Principal | System.Security.Principal.* |
Program | System.InvalidProgramException |
Reference | |
Reflection | System.Reflection.* |
Region | |
Remoting | System.Runtime.Remoting.* |
Resources | System.Resources.* |
Security | System.Security.* |
Serialization | System.Runtime.Serialization.* |
Stack | |
Task | System.Threading.Tasks.* |
Text | System.Text.* |
Threading | System.Threading.* |
TimeZone | |
Type | |
Xml | System.Xml.* |
This document is partially derived from work with following license.
/*This file is a derivate of a source file that has following license (below). ======================================================================== The MIT License (MIT) Copyright (c) Microsoft Corporation Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ======================================================================*/