1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-23 00:58:48 +00:00

Move exception message to the right resource resx

This commit is contained in:
RealityProgrammer 2023-03-14 22:03:21 +07:00
parent 0bf4d7ba77
commit 44165b310d
6 changed files with 198 additions and 96 deletions

View File

@ -77,14 +77,5 @@ namespace X10D {
return ResourceManager.GetString("EnumParseNotEnumException", resourceCulture); return ResourceManager.GetString("EnumParseNotEnumException", resourceCulture);
} }
} }
/// <summary>
/// Looks up a localized string similar to Rune.Utf8SequenceLength returns value outside range 1 to 4 (inclusive), which is unexpected according to the official documentation..
/// </summary>
internal static string RuneUtf8SequenceLengthUnexpectedValue {
get {
return ResourceManager.GetString("RuneUtf8SequenceLengthUnexpectedValue", resourceCulture);
}
}
} }
} }

View File

@ -123,7 +123,4 @@
<data name="EnumParseNotEnumException" xml:space="preserve"> <data name="EnumParseNotEnumException" xml:space="preserve">
<value>Type provided must be an Enum.</value> <value>Type provided must be an Enum.</value>
</data> </data>
<data name="RuneUtf8SequenceLengthUnexpectedValue" xml:space="preserve">
<value>Rune.Utf8SequenceLength returns value outside range 1 to 4 (inclusive), which is unexpected according to the official documentation.</value>
</data>
</root> </root>

View File

@ -411,6 +411,9 @@ public static class SpanExtensions
switch (source.Length) switch (source.Length)
{ {
case > 64: throw new ArgumentException("Source cannot contain more than than 64 elements.", nameof(source)); case > 64: throw new ArgumentException("Source cannot contain more than than 64 elements.", nameof(source));
case 8: return PackByte(source);
case 16: return PackInt16(source);
case 32: return PackInt32(source);
case 64: case 64:
// TODO: Reimplement when Vector512 is in standard API. // TODO: Reimplement when Vector512 is in standard API.
return (long)PackInt32(source[..32]) | ((long)PackInt32(source[32..]) << 32); return (long)PackInt32(source[..32]) | ((long)PackInt32(source[32..]) << 32);

View File

@ -1,6 +1,7 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// <auto-generated> // <auto-generated>
// This code was generated by a tool. // This code was generated by a tool.
// Runtime Version:4.0.30319.42000
// //
// Changes to this file may cause incorrect behavior and will be lost if // Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated. // the code is regenerated.
@ -18,7 +19,7 @@ namespace X10D {
// class via a tool like ResGen or Visual Studio. // class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen // To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project. // with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class ExceptionMessages { internal class ExceptionMessages {
@ -221,6 +222,15 @@ namespace X10D {
} }
} }
/// <summary>
/// Looks up a localized string similar to Rune.Utf8SequenceLength returns value {0} which is outside range 1 to 4 (inclusive), which is unexpected according to the official documentation..
/// </summary>
internal static string UnexpectedRuneUtf8SequenceLength {
get {
return ResourceManager.GetString("UnexpectedRuneUtf8SequenceLength", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Year cannot be zero.. /// Looks up a localized string similar to Year cannot be zero..
/// </summary> /// </summary>

View File

@ -1,83 +1,180 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<root> <root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" <!--
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> Microsoft ResX Schema
<xsd:element name="root" msdata:IsDataSet="true">
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
</xsd:element> mimetype: application/x-microsoft.net.object.bytearray.base64
</xsd:schema> value : The object must be serialized into a byte array
<resheader name="resmimetype"> : using a System.ComponentModel.TypeConverter
<value>text/microsoft-resx</value> : and then encoded with base64 encoding.
</resheader> -->
<resheader name="version"> <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<value>1.3</value> <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
</resheader> <xsd:element name="root" msdata:IsDataSet="true">
<resheader name="reader"> <xsd:complexType>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, <xsd:choice maxOccurs="unbounded">
PublicKeyToken=b77a5c561934e089 <xsd:element name="metadata">
</value> <xsd:complexType>
</resheader> <xsd:sequence>
<resheader name="writer"> <xsd:element name="value" type="xsd:string" minOccurs="0" />
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, </xsd:sequence>
PublicKeyToken=b77a5c561934e089 <xsd:attribute name="name" use="required" type="xsd:string" />
</value> <xsd:attribute name="type" type="xsd:string" />
</resheader> <xsd:attribute name="mimetype" type="xsd:string" />
<data name="BufferTooSmall" xml:space="preserve"> <xsd:attribute ref="xml:space" />
<value>The buffer is too small to contain the data.</value> </xsd:complexType>
</data> </xsd:element>
<data name="CountMustBeInRange" xml:space="preserve"> <xsd:element name="assembly">
<value>Count must be positive and count must refer to a location within the string/array/collection.</value> <xsd:complexType>
</data> <xsd:attribute name="alias" type="xsd:string" />
<data name="EndIndexLessThanStartIndex" xml:space="preserve"> <xsd:attribute name="name" type="xsd:string" />
<value>The end index must be greater than or equal to the start index.</value> </xsd:complexType>
</data> </xsd:element>
<data name="EndIndexGreaterThanCount" xml:space="preserve"> <xsd:element name="data">
<value>The end index must be less than the list count.</value> <xsd:complexType>
</data> <xsd:sequence>
<data name="TypeIsNotClass" xml:space="preserve"> <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<value>{0} is not a class.</value> <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</data> </xsd:sequence>
<data name="TypeIsNotInterface" xml:space="preserve"> <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<value>{0} is not an interface.</value> <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
</data> <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<data name="TypeDoesNotInheritAttribute" xml:space="preserve"> <xsd:attribute ref="xml:space" />
<value>{0} does not inherit {1}</value> </xsd:complexType>
</data> </xsd:element>
<data name="HashAlgorithmNoCreateMethod" xml:space="preserve"> <xsd:element name="resheader">
<value>HashAlgorithm does not offer Create method.</value> <xsd:complexType>
</data> <xsd:sequence>
<data name="HashAlgorithmCreateReturnedNull" xml:space="preserve"> <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<value>HashAlgorithm's Create method returned null reference.</value> </xsd:sequence>
</data> <xsd:attribute name="name" type="xsd:string" use="required" />
<data name="IndexOutOfRange" xml:space="preserve"> </xsd:complexType>
<value>Index was out of range. Must be non-negative and less than or equal to the size of the collection.</value> </xsd:element>
</data> </xsd:choice>
<data name="LengthGreaterThanOrEqualTo0" xml:space="preserve"> </xsd:complexType>
<value>Length must be greater than or equal to 0.</value> </xsd:element>
</data> </xsd:schema>
<data name="StreamDoesNotSupportReading" xml:space="preserve"> <resheader name="resmimetype">
<value>The stream does not support reading.</value> <value>text/microsoft-resx</value>
</data> </resheader>
<data name="StreamDoesNotSupportWriting" xml:space="preserve"> <resheader name="version">
<value>The stream does not support writing.</value> <value>2.0</value>
</data> </resheader>
<data name="StreamTooLarge" xml:space="preserve"> <resheader name="reader">
<value>The length of the stream is too large.</value> <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data> </resheader>
<data name="MaxValueGreaterThanEqualTo0" xml:space="preserve"> <resheader name="writer">
<value>maxValue must be greater than or equal to 0</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data> </resheader>
<data name="MaxValueGreaterThanEqualToMinValue" xml:space="preserve"> <data name="BufferTooSmall" xml:space="preserve">
<value>maxValue must be greater than or equal to minValue</value> <value>The buffer is too small to contain the data.</value>
</data> </data>
<data name="LowerCannotBeGreaterThanUpper" xml:space="preserve"> <data name="CountMustBeInRange" xml:space="preserve">
<value>{0} cannot be greater than {1}</value> <value>Count must be positive and count must refer to a location within the string/array/collection.</value>
</data> </data>
<data name="CountMustBeGreaterThanOrEqualTo0" xml:space="preserve"> <data name="EndIndexLessThanStartIndex" xml:space="preserve">
<value>count must be greater than or equal to 0.</value> <value>The end index must be greater than or equal to the start index.</value>
</data> </data>
<data name="YearCannotBeZero" xml:space="preserve"> <data name="EndIndexGreaterThanCount" xml:space="preserve">
<value>Year cannot be zero.</value> <value>The end index must be less than the list count.</value>
</data> </data>
<data name="TypeIsNotClass" xml:space="preserve">
<value>{0} is not a class.</value>
</data>
<data name="TypeIsNotInterface" xml:space="preserve">
<value>{0} is not an interface.</value>
</data>
<data name="TypeDoesNotInheritAttribute" xml:space="preserve">
<value>{0} does not inherit {1}</value>
</data>
<data name="HashAlgorithmNoCreateMethod" xml:space="preserve">
<value>HashAlgorithm does not offer Create method.</value>
</data>
<data name="HashAlgorithmCreateReturnedNull" xml:space="preserve">
<value>HashAlgorithm's Create method returned null reference.</value>
</data>
<data name="IndexOutOfRange" xml:space="preserve">
<value>Index was out of range. Must be non-negative and less than or equal to the size of the collection.</value>
</data>
<data name="LengthGreaterThanOrEqualTo0" xml:space="preserve">
<value>Length must be greater than or equal to 0.</value>
</data>
<data name="StreamDoesNotSupportReading" xml:space="preserve">
<value>The stream does not support reading.</value>
</data>
<data name="StreamDoesNotSupportWriting" xml:space="preserve">
<value>The stream does not support writing.</value>
</data>
<data name="StreamTooLarge" xml:space="preserve">
<value>The length of the stream is too large.</value>
</data>
<data name="MaxValueGreaterThanEqualTo0" xml:space="preserve">
<value>maxValue must be greater than or equal to 0</value>
</data>
<data name="MaxValueGreaterThanEqualToMinValue" xml:space="preserve">
<value>maxValue must be greater than or equal to minValue</value>
</data>
<data name="LowerCannotBeGreaterThanUpper" xml:space="preserve">
<value>{0} cannot be greater than {1}</value>
</data>
<data name="CountMustBeGreaterThanOrEqualTo0" xml:space="preserve">
<value>count must be greater than or equal to 0.</value>
</data>
<data name="YearCannotBeZero" xml:space="preserve">
<value>Year cannot be zero.</value>
</data>
<data name="UnexpectedRuneUtf8SequenceLength" xml:space="preserve">
<value>Rune.Utf8SequenceLength returns value {0} which is outside range 1 to 4 (inclusive), which is unexpected according to the official documentation.</value>
</data>
</root> </root>

View File

@ -1,6 +1,7 @@
#if NETCOREAPP3_0_OR_GREATER #if NETCOREAPP3_0_OR_GREATER
using System.Diagnostics; using System.Diagnostics;
using System.Diagnostics.Contracts; using System.Diagnostics.Contracts;
using System.Globalization;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
@ -46,9 +47,11 @@ public static class RuneExtensions
return value.ToString(); return value.ToString();
} }
int length = value.Utf8SequenceLength;
// Helpful documentation: https://en.wikipedia.org/wiki/UTF-8 // Helpful documentation: https://en.wikipedia.org/wiki/UTF-8
// This probably gonna break interning but whatever. // This probably gonna break interning but whatever.
switch (value.Utf8SequenceLength) switch (length)
{ {
case 1: case 1:
{ {
@ -66,7 +69,7 @@ public static class RuneExtensions
// Codepoint 0x0080 to 0x07FF convert into 1 .NET character string, directly use string constructor. // Codepoint 0x0080 to 0x07FF convert into 1 .NET character string, directly use string constructor.
unsafe unsafe
{ {
Span<byte> bytes = stackalloc byte[value.Utf8SequenceLength]; Span<byte> bytes = stackalloc byte[length];
value.EncodeToUtf8(bytes); value.EncodeToUtf8(bytes);
char character; char character;
@ -94,10 +97,11 @@ public static class RuneExtensions
} }
default: default:
var msg = string.Format(CultureInfo.CurrentCulture, ExceptionMessages.UnexpectedRuneUtf8SequenceLength, length);
#if NET7_0_OR_GREATER #if NET7_0_OR_GREATER
throw new UnreachableException(Resource.RuneUtf8SequenceLengthUnexpectedValue); throw new UnreachableException(msg);
#else #else
throw new InvalidOperationException(Resource.RuneUtf8SequenceLengthUnexpectedValue); throw new InvalidOperationException(msg);
#endif #endif
} }
} }