From 98f08919d6b06ce0240843ddd7c984fcfd44711c Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 13 Nov 2022 19:59:23 +0000 Subject: [PATCH] Convert to switch expression. --- Marshal.cs | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/Marshal.cs b/Marshal.cs index 49a8651..6611d97 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -249,21 +249,16 @@ public static class Marshal properties)) return ByteArrayToStructureLittleEndian(bytes); - switch(properties.Endian) - { - case BitEndian.Little: - return properties.HasReferences ? ByteArrayToStructureLittleEndian(bytes) - : SpanToStructureLittleEndian(bytes); - - case BitEndian.Big: - return properties.HasReferences ? ByteArrayToStructureBigEndian(bytes) - : SpanToStructureBigEndian(bytes); - - case BitEndian.Pdp: - return properties.HasReferences ? ByteArrayToStructurePdpEndian(bytes) - : SpanToStructurePdpEndian(bytes); - default: throw new ArgumentOutOfRangeException(); - } + return properties.Endian switch + { + BitEndian.Little => properties.HasReferences ? ByteArrayToStructureLittleEndian(bytes) + : SpanToStructureLittleEndian(bytes), + BitEndian.Big => properties.HasReferences ? ByteArrayToStructureBigEndian(bytes) + : SpanToStructureBigEndian(bytes), + BitEndian.Pdp => properties.HasReferences ? ByteArrayToStructurePdpEndian(bytes) + : SpanToStructurePdpEndian(bytes), + _ => throw new ArgumentOutOfRangeException() + }; } /// Swaps all members of a structure