From 1a059d50fcbc03c1cbfb3a24f750dc3975ff562d Mon Sep 17 00:00:00 2001 From: jan zens <89642092+sneznaj@users.noreply.github.com> Date: Thu, 2 Dec 2021 11:41:18 +0100 Subject: [PATCH 1/2] Use pattern matching in PayloadHelper.cs to improve readability Improves the readability using c# pattern matching fixes #25 --- .../Interop/Ipc/PayloadHelper.cs | 47 ++++--------------- 1 file changed, 10 insertions(+), 37 deletions(-) diff --git a/src/csharp/Microsoft.Spark/Interop/Ipc/PayloadHelper.cs b/src/csharp/Microsoft.Spark/Interop/Ipc/PayloadHelper.cs index 3373bca62..bf1349c29 100644 --- a/src/csharp/Microsoft.Spark/Interop/Ipc/PayloadHelper.cs +++ b/src/csharp/Microsoft.Spark/Interop/Ipc/PayloadHelper.cs @@ -323,15 +323,6 @@ internal static byte[] GetTypeId(Type type) case TypeCode.Double: return s_doubleTypeId; case TypeCode.Object: - if (typeof(IJvmObjectReferenceProvider).IsAssignableFrom(type)) - { - return s_jvmObjectTypeId; - } - - if (type == typeof(byte[])) - { - return s_byteArrayTypeId; - } if (type == typeof(int[]) || type == typeof(long[]) || @@ -343,35 +334,17 @@ internal static byte[] GetTypeId(Type type) return s_arrayTypeId; } - if (IsDictionary(type)) - { - return s_dictionaryTypeId; - } - - if (typeof(IEnumerable).IsAssignableFrom(type)) - { - return s_arrayTypeId; - } - - if (typeof(IEnumerable).IsAssignableFrom(type)) - { - return s_rowArrTypeId; - } - - if (typeof(IEnumerable).IsAssignableFrom(type)) + return type switch { - return s_objectArrTypeId; - } - - if (typeof(Date).IsAssignableFrom(type)) - { - return s_dateTypeId; - } - - if (typeof(Timestamp).IsAssignableFrom(type)) - { - return s_timestampTypeId; - } + _ when typeof(IJvmObjectReferenceProvider).IsAssignableFrom(type) => s_jvmObjectTypeId, + _ when type == typeof(byte[]) => s_byteArrayTypeId, + _ when IsDictionary(type) => s_dictionaryTypeId, + _ when typeof(IEnumerable).IsAssignableFrom(type) => s_arrayTypeId, + _ when typeof(IEnumerable).IsAssignableFrom(type) => s_rowArrTypeId, + _ when typeof(IEnumerable).IsAssignableFrom(type) => s_objectArrTypeId, + _ when typeof(Date).IsAssignableFrom(type) => s_dateTypeId, + _ when typeof(Timestamp).IsAssignableFrom(type) => s_timestampTypeId, + }; break; } From 9a39771541a25033177f3274fac6cdbc047eea22 Mon Sep 17 00:00:00 2001 From: jan zens <89642092+sneznaj@users.noreply.github.com> Date: Wed, 8 Dec 2021 01:37:45 +0100 Subject: [PATCH 2/2] remove unreachable break command --- src/csharp/Microsoft.Spark/Interop/Ipc/PayloadHelper.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/csharp/Microsoft.Spark/Interop/Ipc/PayloadHelper.cs b/src/csharp/Microsoft.Spark/Interop/Ipc/PayloadHelper.cs index bf1349c29..bfe77caad 100644 --- a/src/csharp/Microsoft.Spark/Interop/Ipc/PayloadHelper.cs +++ b/src/csharp/Microsoft.Spark/Interop/Ipc/PayloadHelper.cs @@ -345,7 +345,6 @@ internal static byte[] GetTypeId(Type type) _ when typeof(Date).IsAssignableFrom(type) => s_dateTypeId, _ when typeof(Timestamp).IsAssignableFrom(type) => s_timestampTypeId, }; - break; } // TODO: Support other types.