Skip to content

Commit 1a059d5

Browse files
committed
Use pattern matching in PayloadHelper.cs to improve readability
Improves the readability using c# pattern matching fixes dotnet#25
1 parent b0a3068 commit 1a059d5

File tree

1 file changed

+10
-37
lines changed

1 file changed

+10
-37
lines changed

src/csharp/Microsoft.Spark/Interop/Ipc/PayloadHelper.cs

+10-37
Original file line numberDiff line numberDiff line change
@@ -323,15 +323,6 @@ internal static byte[] GetTypeId(Type type)
323323
case TypeCode.Double:
324324
return s_doubleTypeId;
325325
case TypeCode.Object:
326-
if (typeof(IJvmObjectReferenceProvider).IsAssignableFrom(type))
327-
{
328-
return s_jvmObjectTypeId;
329-
}
330-
331-
if (type == typeof(byte[]))
332-
{
333-
return s_byteArrayTypeId;
334-
}
335326

336327
if (type == typeof(int[]) ||
337328
type == typeof(long[]) ||
@@ -343,35 +334,17 @@ internal static byte[] GetTypeId(Type type)
343334
return s_arrayTypeId;
344335
}
345336

346-
if (IsDictionary(type))
347-
{
348-
return s_dictionaryTypeId;
349-
}
350-
351-
if (typeof(IEnumerable<IJvmObjectReferenceProvider>).IsAssignableFrom(type))
352-
{
353-
return s_arrayTypeId;
354-
}
355-
356-
if (typeof(IEnumerable<GenericRow>).IsAssignableFrom(type))
357-
{
358-
return s_rowArrTypeId;
359-
}
360-
361-
if (typeof(IEnumerable<object>).IsAssignableFrom(type))
337+
return type switch
362338
{
363-
return s_objectArrTypeId;
364-
}
365-
366-
if (typeof(Date).IsAssignableFrom(type))
367-
{
368-
return s_dateTypeId;
369-
}
370-
371-
if (typeof(Timestamp).IsAssignableFrom(type))
372-
{
373-
return s_timestampTypeId;
374-
}
339+
_ when typeof(IJvmObjectReferenceProvider).IsAssignableFrom(type) => s_jvmObjectTypeId,
340+
_ when type == typeof(byte[]) => s_byteArrayTypeId,
341+
_ when IsDictionary(type) => s_dictionaryTypeId,
342+
_ when typeof(IEnumerable<IJvmObjectReferenceProvider>).IsAssignableFrom(type) => s_arrayTypeId,
343+
_ when typeof(IEnumerable<GenericRow>).IsAssignableFrom(type) => s_rowArrTypeId,
344+
_ when typeof(IEnumerable<object>).IsAssignableFrom(type) => s_objectArrTypeId,
345+
_ when typeof(Date).IsAssignableFrom(type) => s_dateTypeId,
346+
_ when typeof(Timestamp).IsAssignableFrom(type) => s_timestampTypeId,
347+
};
375348
break;
376349
}
377350

0 commit comments

Comments
 (0)