public void CanItemHeaderGetItemBufferWithRawHeaderData(SecsFormat expectedSecsFormat, int expectedItemLength, byte expectedNumberOfLengthBytes, byte expectedRawHeaderDataSize) { ItemHeader itemHeader = new ItemHeader(expectedSecsFormat, expectedItemLength); byte[] expectedItemBufferWithRawHeaderData = new byte[expectedRawHeaderDataSize + expectedItemLength]; expectedItemBufferWithRawHeaderData[0] = (byte)((int)expectedSecsFormat | expectedNumberOfLengthBytes); switch (expectedNumberOfLengthBytes) { case 1: expectedItemBufferWithRawHeaderData[1] = (byte)expectedItemLength; break; case 2: expectedItemBufferWithRawHeaderData[1] = (byte)(expectedItemLength >> 8); expectedItemBufferWithRawHeaderData[2] = (byte)expectedItemLength; break; case 3: expectedItemBufferWithRawHeaderData[1] = (byte)(expectedItemLength >> 16); expectedItemBufferWithRawHeaderData[2] = (byte)(expectedItemLength >> 8); expectedItemBufferWithRawHeaderData[3] = (byte)expectedItemLength; break; default: throw new ArgumentOutOfRangeException(nameof(expectedNumberOfLengthBytes), expectedNumberOfLengthBytes, "The argument must be 1, 2 or 3."); } var(actualItemBufferWithRawHeaderData, actualOffset) = itemHeader.GetItemBufferWithRawHeaderData(); Assert.AreEqual(expectedRawHeaderDataSize, actualOffset, nameof(actualOffset)); CollectionAssert.AreEqual(expectedItemBufferWithRawHeaderData, actualItemBufferWithRawHeaderData); }
internal static Item BytesDecode(this SecsFormat format) { switch (format) { case SecsFormat.ASCII: return(A()); case SecsFormat.JIS8: return(J()); case SecsFormat.Boolean: return(Boolean()); case SecsFormat.Binary: return(B()); case SecsFormat.U1: return(U1()); case SecsFormat.U2: return(U2()); case SecsFormat.U4: return(U4()); case SecsFormat.U8: return(U8()); case SecsFormat.I1: return(I1()); case SecsFormat.I2: return(I2()); case SecsFormat.I4: return(I4()); case SecsFormat.I8: return(I8()); case SecsFormat.F4: return(F4()); case SecsFormat.F8: return(F8()); } throw new ArgumentException(@"Invalid format:" + format, nameof(format)); }
public static string ToSML(this SecsFormat format) { switch (format) { case SecsFormat.List: return("L"); case SecsFormat.Binary: return("B"); case SecsFormat.Boolean: return("Boolean"); case SecsFormat.ASCII: return("A"); case SecsFormat.JIS8: return("J"); case SecsFormat.I8: return("I8"); case SecsFormat.I1: return("I1"); case SecsFormat.I2: return("I2"); case SecsFormat.I4: return("I4"); case SecsFormat.F8: return("F8"); case SecsFormat.F4: return("F4"); case SecsFormat.U8: return("U8"); case SecsFormat.U1: return("U1"); case SecsFormat.U2: return("U2"); default /* SecsFormat.U4 */: return("U4"); } }
internal static Item BytesDecode(this SecsFormat format, byte[] data, ref int index, ref int length) { switch (format) { case SecsFormat.ASCII: return(A(Encoding.ASCII.GetString(data, index, length))); case SecsFormat.JIS8: return(J(JIS8Encoding.GetString(data, index, length))); case SecsFormat.Boolean: return(Boolean(Decode <bool>(data, ref index, ref length))); case SecsFormat.Binary: return(B(Decode <byte>(data, ref index, ref length))); case SecsFormat.U1: return(U1(Decode <byte>(data, ref index, ref length))); case SecsFormat.U2: return(U2(Decode <ushort>(data, ref index, ref length))); case SecsFormat.U4: return(U4(Decode <uint>(data, ref index, ref length))); case SecsFormat.U8: return(U8(Decode <ulong>(data, ref index, ref length))); case SecsFormat.I1: return(I1(Decode <sbyte>(data, ref index, ref length))); case SecsFormat.I2: return(I2(Decode <short>(data, ref index, ref length))); case SecsFormat.I4: return(I4(Decode <int>(data, ref index, ref length))); case SecsFormat.I8: return(I8(Decode <long>(data, ref index, ref length))); case SecsFormat.F4: return(F4(Decode <float>(data, ref index, ref length))); case SecsFormat.F8: return(F8(Decode <double>(data, ref index, ref length))); } throw new ArgumentException(@"Invalid format", nameof(format)); }
internal static Item BytesDecode(this SecsFormat format, byte[] bytes, int index, int length) { switch (format) { case SecsFormat.ASCII: return(Item.A(Encoding.ASCII.GetString(bytes, index, length))); case SecsFormat.JIS8: return(Item.J(Item.JIS8Encoding.GetString(bytes, index, length))); case SecsFormat.Boolean: return(Item.Boolean(Decode <bool>(sizeof(bool), bytes, index, length))); case SecsFormat.Binary: return(Item.B(Decode <byte>(sizeof(byte), bytes, index, length))); case SecsFormat.U1: return(Item.U1(Decode <byte>(sizeof(byte), bytes, index, length))); case SecsFormat.U2: return(Item.U2(Decode <ushort>(sizeof(ushort), bytes, index, length))); case SecsFormat.U4: return(Item.U4(Decode <uint>(sizeof(uint), bytes, index, length))); case SecsFormat.U8: return(Item.U8(Decode <ulong>(sizeof(ulong), bytes, index, length))); case SecsFormat.I1: return(Item.I1(Decode <sbyte>(sizeof(sbyte), bytes, index, length))); case SecsFormat.I2: return(Item.I2(Decode <short>(sizeof(short), bytes, index, length))); case SecsFormat.I4: return(Item.I4(Decode <int>(sizeof(int), bytes, index, length))); case SecsFormat.I8: return(Item.I8(Decode <long>(sizeof(long), bytes, index, length))); case SecsFormat.F4: return(Item.F4(Decode <float>(sizeof(float), bytes, index, length))); case SecsFormat.F8: return(Item.F8(Decode <double>(sizeof(double), bytes, index, length))); } throw new ArgumentException("Invalid format:" + format, "format"); }
/// <summary> /// Empty Item(none List) /// </summary> /// <param name="format"></param> /// <param name="value"></param> Item(SecsFormat format, ICloneable value) { Format = format; Value = value; _rawBytes = Lazy.Create(new RawData(new byte[] { (byte)((byte)Format | 1), 0 })); _sml = EmptySml; }
/// <summary> /// Encode Item header + value (initial array only) /// </summary> /// <param name="format">items format</param> /// <param name="valueCount">items value count</param> /// <param name="headerlength">header bytes length</param> /// <returns></returns> internal static byte[] EncodeItem(this SecsFormat format, int valueCount, out int headerlength) { byte[] lengthBytes = BitConverter.GetBytes(valueCount); int dataLength = format == SecsFormat.List ? 0 : valueCount; if (valueCount <= 0xff) // 1 byte { headerlength = 2; var result = new byte[dataLength + 2]; result[0] = (byte)((byte)format | 1); result[1] = lengthBytes[0]; return(result); } if (valueCount <= 0xffff) // 2 byte { headerlength = 3; var result = new byte[dataLength + 3]; result[0] = (byte)((byte)format | 2); result[1] = lengthBytes[1]; result[2] = lengthBytes[0]; return(result); } if (valueCount <= 0xffffff) // 3 byte { headerlength = 4; var result = new byte[dataLength + 4]; result[0] = (byte)((byte)format | 3); result[1] = lengthBytes[2]; result[2] = lengthBytes[1]; result[3] = lengthBytes[0]; return(result); } throw new ArgumentOutOfRangeException("byteLength", valueCount, String.Format("Item data length({0}) is overflow", valueCount)); }
internal static Item BytesDecode(this SecsFormat format) { switch (format) { case SecsFormat.ASCII: return(Item.A()); case SecsFormat.JIS8: return(Item.J()); case SecsFormat.Boolean: return(Item.Boolean()); case SecsFormat.Binary: return(Item.B()); case SecsFormat.U1: return(Item.U1()); case SecsFormat.U2: return(Item.U2()); case SecsFormat.U4: return(Item.U4()); case SecsFormat.U8: return(Item.U8()); case SecsFormat.I1: return(Item.I1()); case SecsFormat.I2: return(Item.I2()); case SecsFormat.I4: return(Item.I4()); case SecsFormat.I8: return(Item.I8()); case SecsFormat.F4: return(Item.F4()); case SecsFormat.F8: return(Item.F8()); } throw new ArgumentException("Invalid format:" + format, "format"); }
private protected static void EncodeItemHeader(SecsFormat format, int count, IBufferWriter <byte> buffer) { var lengthSpan = Unsafe.AsRef(count).AsBytes(); var formatByte = (int)format << 2; if (count <= 0xff) {// 1 byte var span = buffer.GetSpan(sizeHint: 2); span.DangerousGetReferenceAt(0) = (byte)(formatByte | 1); span.DangerousGetReferenceAt(1) = lengthSpan.DangerousGetReferenceAt(0); buffer.Advance(2); return; } if (count <= 0xffff) {// 2 byte var span = buffer.GetSpan(sizeHint: 3); span.DangerousGetReferenceAt(0) = (byte)(formatByte | 2); span.DangerousGetReferenceAt(1) = lengthSpan.DangerousGetReferenceAt(1); span.DangerousGetReferenceAt(2) = lengthSpan.DangerousGetReferenceAt(0); buffer.Advance(3); return; } if (count <= 0xffffff) {// 3 byte var span = buffer.GetSpan(sizeHint: 4); span.DangerousGetReferenceAt(0) = (byte)(formatByte | 3); span.DangerousGetReferenceAt(1) = lengthSpan.DangerousGetReferenceAt(2); span.DangerousGetReferenceAt(2) = lengthSpan.DangerousGetReferenceAt(1); span.DangerousGetReferenceAt(3) = lengthSpan.DangerousGetReferenceAt(0); buffer.Advance(4); return; } ThrowHelper(count);
/// <summary> /// A,J /// </summary> private Item(SecsFormat format, string value) { switch (format) { case SecsFormat.ASCII: case SecsFormat.JIS8: break; default: throw new NotImplementedException($"The format \"{nameof(SecsFormat)}.{format}\" is not implemented within this constructor."); } this.Format = format; this.values = value; this.rawData = new Lazy <byte[]>(() => { var stringValue = Unsafe.As <string>(this.values); var itemHeader = new ItemHeader(this.Format, stringValue.Length); var(result, headerLength) = itemHeader.GetItemBufferWithRawHeaderData(); var encoder = this.Format == SecsFormat.ASCII ? Encoding.ASCII : Item.Jis8Encoding; encoder.GetBytes(stringValue, 0, stringValue.Length, result, headerLength); return(result); }); }
internal LazyStringItem(SecsFormat format, IMemoryOwner <byte> owner) : base(format) { _owner = owner; _value = new Lazy <string>(() => { var encoding = Format == SecsFormat.ASCII ? Encoding.ASCII : Jis8Encoding; return(encoding.GetString(_owner.Memory.Span)); }, isThreadSafe: false); }
// 2: get _format + lengtnBits(2bit) 1 byte private int GetItemHeader(ref int length, out int need) { if (!CheckAvailable(ref length, 1, out need)) { return(2); } _format = (SecsFormat)(_buffer[_decodeIndex] & 0b1111_1100); _lengthBits = (byte)(_buffer[_decodeIndex] & 0b0000_0011); _decodeIndex++; _messageDataLength--; length--; return(GetItemLength(ref length, out need)); }
/// <summary> /// A,J /// </summary> Item(SecsFormat format, string value, Encoding encoder) { Format = format; Count = value.Length; Value = value; _sml = Lazy.Create(value); _rawBytes = Lazy.Create(() => { string str = (string)Value; int headerLength; byte[] result = Format.EncodeItem(str.Length, out headerLength); encoder.GetBytes(str, 0, str.Length, result, headerLength); return(new RawData(result)); }); }
/// <summary> /// ASCII, Jis /// </summary> /// <param name="secsFormat"></param> /// <param name="value"></param> private Item(SecsFormat secsFormat, string value) { Format = secsFormat; _values = value; _rawData = new Lazy <byte[]>(() => { var str = (string)_values; var bytelength = str.Length; var result = EncodeItem(bytelength); var encoder = Format == SecsFormat.ASCII ? Encoding.ASCII : Jis8Encoding; encoder.GetBytes(str, 0, str.Length, result.Item1, result.Item2); return(result.Item1); }); }
internal static Item BytesDecode(ref SecsFormat secsFormat, byte[] data, ref int index, ref int length) { switch (secsFormat) { case SecsFormat.ASCII: return(length == 0 ? A() : A(Encoding.ASCII.GetString(data, index, length))); case SecsFormat.Binary: return(length == 0 ? B() : B(Decode <byte>(data, ref index, ref length, sizeof(byte)))); default: throw new ArgumentException(@"Invalid format", nameof(secsFormat)); } }
/// <summary> /// A,J /// </summary> private Item(SecsFormat format, string value) { Format = format; _values = value; _rawData = new Lazy <byte[]>(() => { var str = Unsafe.As <string>(_values); var bytelength = str.Length; var(result, headerLength) = EncodeItem(bytelength); var encoder = Format == SecsFormat.ASCII ? Encoding.ASCII : Jis8Encoding; encoder.GetBytes(str, 0, str.Length, result, headerLength); return(result); }); }
/// <summary> /// U1, U2, U4, U8 /// I1, I2, I4, I8 /// F4, F8 /// Boolean, /// Binary /// </summary> private Item(SecsFormat format, Array value) { Format = format; _values = value; _rawData = new Lazy <byte[]>(() => { var arr = Unsafe.As <Array>(_values); var bytelength = Buffer.ByteLength(arr); var(result, headerLength) = EncodeItem(bytelength); Buffer.BlockCopy(arr, 0, result, headerLength, bytelength); result.Reverse(headerLength, headerLength + bytelength, bytelength / arr.Length); return(result); }); }
/// <summary> /// Decoder step 2: get _format + lengthBits(2bit) 1 byte /// </summary> /// <param name="length"></param> /// <param name="need"></param> /// <returns>The decoder step to execute next.</returns> private int DecoderStep2GetItemHeader(ref int length, out int need) { if (!StreamDecoder.CheckAvailable(length, 1, out need)) { return(2); } this.format = (SecsFormat)(this.Buffer[this.decodeIndex] & 0xFC); this.lengthBits = (byte)(this.Buffer[this.decodeIndex] & 3); this.decodeIndex++; this.messageDataLength--; length--; return(this.DecoderStep3GetItemLength(ref length, out need)); }
/// <summary> /// A,J /// </summary> Item(SecsFormat format, string value) { Format = format; _values = value; RawData = new Lazy <byte[]>(() => { var str = (string)_values; int bytelength = str.Length; int headerLength; byte[] result = EncodeItem(bytelength, out headerLength); var encoder = Format == SecsFormat.ASCII ? Encoding.ASCII : JIS8Encoding; encoder.GetBytes(str, 0, str.Length, result, headerLength); return(result); }); }
/// <summary> /// U2,U4,U8 /// I1,I2,I4,I8 /// F4,F8 /// Boolean /// </summary> Item(SecsFormat format, Array value) { Format = format; _values = value; RawData = new Lazy <byte[]>(() => { var arr = (Array)_values; int bytelength = Buffer.ByteLength(arr); int headerLength; byte[] result = EncodeItem(bytelength, out headerLength); Buffer.BlockCopy(arr, 0, result, headerLength, bytelength); result.Reverse(headerLength, headerLength + bytelength, bytelength / arr.Length); return(result); }); }
/// <summary> /// U2,U4,U8 /// I1,I2,I4,I8 /// F4,F8 /// Boolean /// </summary> Item(SecsFormat format, Array value, Func <string> sml) { Format = format; Count = value.Length; Value = value; _sml = Lazy.Create(sml); _rawBytes = Lazy.Create(() => { Array val = (Array)Value; int bytelength = Buffer.ByteLength(val); int headerLength; byte[] result = Format.EncodeItem(bytelength, out headerLength); Buffer.BlockCopy(val, 0, result, headerLength, bytelength); result.Reverse(headerLength, headerLength + bytelength, bytelength / val.Length); return(new RawData(result)); }); }
/// <summary> /// U1, U2, U4, U8 /// I1, I2, I4, I8 /// F4, F8 /// Boolean, /// Binary /// </summary> /// <param name="secsFormat"></param> /// <param name="value"></param> private Item(SecsFormat secsFormat, Array value) { Format = secsFormat; _values = value; _rawData = new Lazy <byte[]>(() => { var arr = (Array)_values; var byteLength = Buffer.ByteLength(arr); var ret = EncodeItem(byteLength); var result = ret.Item1; var headerLength = ret.Item2; Buffer.BlockCopy(arr, 0, result, headerLength, byteLength); result.Reverse(headerLength, headerLength + byteLength, byteLength / arr.Length); return(result); }); }
public static string ToSml(this SecsFormat secsFormat) { switch (secsFormat) { case SecsFormat.List: return("L"); case SecsFormat.ASCII: return("A"); case SecsFormat.Binary: return("B"); default: throw new ArgumentOutOfRangeException(nameof(secsFormat), (int)secsFormat, "Invalid enum value"); } }
internal static Item BytesDecode(SecsFormat format, byte[] data, int index, int length) { switch (format) { case SecsFormat.ASCII: return(length == 0 ? A() : A(Encoding.ASCII.GetString(data, index, length))); case SecsFormat.JIS8: return(length == 0 ? J() : J(Jis8Encoding.GetString(data, index, length))); case SecsFormat.Boolean: return(length == 0 ? Boolean() : Boolean(Decode <bool>(data, index, length))); case SecsFormat.Binary: return(length == 0 ? B() : B(Decode <byte>(data, index, length))); case SecsFormat.U1: return(length == 0 ? U1() : U1(Decode <byte>(data, index, length))); case SecsFormat.U2: return(length == 0 ? U2() : U2(Decode <ushort>(data, index, length))); case SecsFormat.U4: return(length == 0 ? U4() : U4(Decode <uint>(data, index, length))); case SecsFormat.U8: return(length == 0 ? U8() : U8(Decode <ulong>(data, index, length))); case SecsFormat.I1: return(length == 0 ? I1() : I1(Decode <sbyte>(data, index, length))); case SecsFormat.I2: return(length == 0 ? I2() : I2(Decode <short>(data, index, length))); case SecsFormat.I4: return(length == 0 ? I4() : I4(Decode <int>(data, index, length))); case SecsFormat.I8: return(length == 0 ? I8() : I8(Decode <long>(data, index, length))); case SecsFormat.F4: return(length == 0 ? F4() : F4(Decode <float>(data, index, length))); case SecsFormat.F8: return(length == 0 ? F8() : F8(Decode <double>(data, index, length))); default: throw new ArgumentException("Invalid format", nameof(format)); } T[] Decode <T>(byte[] data2, int index2, int length2) where T : unmanaged { var elmSize = Unsafe.SizeOf <T>(); data2.Reverse(index2, index2 + length2, elmSize); var values = new T[length2 / elmSize]; Buffer.BlockCopy(data2, index2, values, 0, length2); return(values); } }
/// <summary> /// U1, U2, U4, U8 /// I1, I2, I4, I8 /// F4, F8 /// Boolean, /// Binary /// </summary> private Item(SecsFormat format, Array value) { switch (format) { case SecsFormat.Binary: case SecsFormat.Boolean: case SecsFormat.I8: case SecsFormat.I1: case SecsFormat.I2: case SecsFormat.I4: case SecsFormat.F8: case SecsFormat.F4: case SecsFormat.U8: case SecsFormat.U1: case SecsFormat.U2: case SecsFormat.U4: break; default: throw new NotImplementedException($"The format \"{nameof(SecsFormat)}.{format}\" is not implemented within this constructor."); } this.Format = format; this.values = value; this.rawData = new Lazy <byte[]>(() => { var array = Unsafe.As <Array>(this.values); var bytelength = Buffer.ByteLength(array); var itemHeader = new ItemHeader(this.Format, bytelength); var(result, headerLength) = itemHeader.GetItemBufferWithRawHeaderData(); Buffer.BlockCopy(array, 0, result, headerLength, bytelength); if (BitConverter.IsLittleEndian) { result.Reverse(headerLength, headerLength + bytelength, bytelength / array.Length); } return(result); }); }
/// <summary> /// <para xml:lang="en">Initializes a <see langword="new"/> instance of the <see cref="ItemHeader"/> <see langword="struct"/> .</para> /// </summary> /// <param name="secsFormat"><para xml:lang="en">The <see cref="SecsFormat"/> of this instance.</para></param> /// <param name="itemLength"><para xml:lang="en">The length of the item of this instance.</para></param> /// <exception cref="ArgumentOutOfRangeException"><para xml:lang="en"><paramref name="itemLength"/> is less than zero (0).</para></exception> /// <exception cref="ArgumentOutOfRangeException"><para xml:lang="en"><paramref name="itemLength"/> greater than <see cref="ItemHeader.MaxLength"/>.</para></exception> public ItemHeader(SecsFormat secsFormat, int itemLength) { if (itemLength < 0) { throw new ArgumentOutOfRangeException(nameof(itemLength), itemLength, "The argument is less than zero (0)."); } if (itemLength > ItemHeader.MaxLength) { throw new ArgumentOutOfRangeException(nameof(itemLength), itemLength, $"The argument is greater than {ItemHeader.MaxLength}."); } this.itemFormatCodeAndNumberOfLengthBytes = 0; this.lengthByteOne = 0; this.lengthByteTwo = 0; this.lengthByteThree = 0; this.itemLength = itemLength; if (!BitConverter.IsLittleEndian) { byte temp = this.lengthByteThree; this.lengthByteThree = this.itemFormatCodeAndNumberOfLengthBytes; this.itemFormatCodeAndNumberOfLengthBytes = temp; temp = this.lengthByteTwo; this.lengthByteTwo = this.lengthByteOne; this.lengthByteOne = temp; } if (itemLength <= byte.MaxValue) { this.itemFormatCodeAndNumberOfLengthBytes = (byte)((int)secsFormat | 1); } else if (itemLength <= ushort.MaxValue) { this.itemFormatCodeAndNumberOfLengthBytes = (byte)((int)secsFormat | 2); } else { this.itemFormatCodeAndNumberOfLengthBytes = (byte)((int)secsFormat | 3); } }
public static string ToSML(this SecsFormat format) { switch (format) { case SecsFormat.List: return "L"; case SecsFormat.Binary: return "B"; case SecsFormat.Boolean: return "Boolean"; case SecsFormat.ASCII: return "A"; case SecsFormat.JIS8: return "J"; case SecsFormat.I8: return "I8"; case SecsFormat.I1: return "I1"; case SecsFormat.I2: return "I2"; case SecsFormat.I4: return "I4"; case SecsFormat.F8: return "F8"; case SecsFormat.F4: return "F4"; case SecsFormat.U8: return "U8"; case SecsFormat.U1: return "U1"; case SecsFormat.U2: return "U2"; case SecsFormat.U4: return "U4"; default: throw new ArgumentException("invalid format", nameof(format)); } }
public static string GetName(this SecsFormat format) { return(format switch { SecsFormat.List => nameof(SecsFormat.List), SecsFormat.Binary => nameof(SecsFormat.Binary), SecsFormat.Boolean => nameof(SecsFormat.Boolean), SecsFormat.ASCII => nameof(SecsFormat.ASCII), SecsFormat.JIS8 => nameof(SecsFormat.JIS8), SecsFormat.I8 => nameof(SecsFormat.I8), SecsFormat.I1 => nameof(SecsFormat.I1), SecsFormat.I2 => nameof(SecsFormat.I2), SecsFormat.I4 => nameof(SecsFormat.I4), SecsFormat.F8 => nameof(SecsFormat.F8), SecsFormat.F4 => nameof(SecsFormat.F4), SecsFormat.U8 => nameof(SecsFormat.U8), SecsFormat.U1 => nameof(SecsFormat.U1), SecsFormat.U2 => nameof(SecsFormat.U2), SecsFormat.U4 => nameof(SecsFormat.U4), _ => ThrowHelper(format), });
public static string ToSml(this SecsFormat format) { switch (format) { case SecsFormat.List: return("L"); case SecsFormat.Binary: return("B"); case SecsFormat.Boolean: return("Boolean"); case SecsFormat.ASCII: return("A"); case SecsFormat.JIS8: return("J"); case SecsFormat.I8: return("I8"); case SecsFormat.I1: return("I1"); case SecsFormat.I2: return("I2"); case SecsFormat.I4: return("I4"); case SecsFormat.F8: return("F8"); case SecsFormat.F4: return("F4"); case SecsFormat.U8: return("U8"); case SecsFormat.U1: return("U1"); case SecsFormat.U2: return("U2"); case SecsFormat.U4: return("U4"); default: throw new ArgumentOutOfRangeException(nameof(format), (int)format, "Invalid enum value"); } }
public static string GetName(this SecsFormat format) { switch (format) { case SecsFormat.List: return(nameof(SecsFormat.List)); case SecsFormat.ASCII: return(nameof(SecsFormat.ASCII)); case SecsFormat.JIS8: return(nameof(SecsFormat.JIS8)); case SecsFormat.Boolean: return(nameof(SecsFormat.Boolean)); case SecsFormat.Binary: return(nameof(SecsFormat.Binary)); case SecsFormat.U1: return(nameof(SecsFormat.U1)); case SecsFormat.U2: return(nameof(SecsFormat.U2)); case SecsFormat.U4: return(nameof(SecsFormat.U4)); case SecsFormat.U8: return(nameof(SecsFormat.U8)); case SecsFormat.I1: return(nameof(SecsFormat.I1)); case SecsFormat.I2: return(nameof(SecsFormat.I2)); case SecsFormat.I4: return(nameof(SecsFormat.I4)); case SecsFormat.I8: return(nameof(SecsFormat.I8)); case SecsFormat.F4: return(nameof(SecsFormat.F4)); case SecsFormat.F8: return(nameof(SecsFormat.F8)); default: throw new ArgumentOutOfRangeException(nameof(format), (int)format, "Invalid enum value."); } }