1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-22 19:48:46 +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);
}
}
/// <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">
<value>Type provided must be an Enum.</value>
</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>

View File

@ -411,6 +411,9 @@ public static class SpanExtensions
switch (source.Length)
{
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:
// TODO: Reimplement when Vector512 is in standard API.
return (long)PackInt32(source[..32]) | ((long)PackInt32(source[32..]) << 32);

View File

@ -1,6 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 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
// the code is regenerated.
@ -18,7 +19,7 @@ namespace X10D {
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// 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.Runtime.CompilerServices.CompilerGeneratedAttribute()]
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>
/// Looks up a localized string similar to Year cannot be zero..
/// </summary>

View File

@ -1,83 +1,180 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<!--
Microsoft ResX Schema
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>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
</resheader>
<data name="BufferTooSmall" xml:space="preserve">
<value>The buffer is too small to contain the data.</value>
</data>
<data name="CountMustBeInRange" xml:space="preserve">
<value>Count must be positive and count must refer to a location within the string/array/collection.</value>
</data>
<data name="EndIndexLessThanStartIndex" xml:space="preserve">
<value>The end index must be greater than or equal to the start index.</value>
</data>
<data name="EndIndexGreaterThanCount" xml:space="preserve">
<value>The end index must be less than the list count.</value>
</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>
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="BufferTooSmall" xml:space="preserve">
<value>The buffer is too small to contain the data.</value>
</data>
<data name="CountMustBeInRange" xml:space="preserve">
<value>Count must be positive and count must refer to a location within the string/array/collection.</value>
</data>
<data name="EndIndexLessThanStartIndex" xml:space="preserve">
<value>The end index must be greater than or equal to the start index.</value>
</data>
<data name="EndIndexGreaterThanCount" xml:space="preserve">
<value>The end index must be less than the list count.</value>
</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>

View File

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