Contribute to IDE0019 (use pattern matching) and IDE0066 (use switch expression)
authorStephen Toub <stoub@microsoft.com>
Fri, 9 Aug 2019 15:55:23 +0000 (11:55 -0400)
committerStephen Toub <stoub@microsoft.com>
Tue, 13 Aug 2019 15:49:18 +0000 (11:49 -0400)
Commit migrated from https://github.com/dotnet/coreclr/commit/c052397f92ad73bcf8b30281eec3cb85abdb3b56

40 files changed:
src/coreclr/src/System.Private.CoreLib/src/System/Attribute.CoreCLR.cs
src/coreclr/src/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs
src/coreclr/src/System.Private.CoreLib/src/System/Reflection/MdConstant.cs
src/coreclr/src/System.Private.CoreLib/src/System/Reflection/MdFieldInfo.cs
src/coreclr/src/System.Private.CoreLib/src/System/Reflection/RtFieldInfo.cs
src/coreclr/src/System.Private.CoreLib/src/System/Reflection/RuntimeConstructorInfo.cs
src/coreclr/src/System.Private.CoreLib/src/System/Reflection/RuntimeEventInfo.cs
src/coreclr/src/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs
src/coreclr/src/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs
src/coreclr/src/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs
src/coreclr/src/System.Private.CoreLib/src/System/StubHelpers.cs
src/coreclr/src/System.Private.CoreLib/src/System/Variant.cs
src/libraries/System.Private.CoreLib/src/System/AggregateException.cs
src/libraries/System.Private.CoreLib/src/System/Array.cs
src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.cs
src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Date.cs
src/libraries/System.Private.CoreLib/src/System/Collections/ArrayList.cs
src/libraries/System.Private.CoreLib/src/System/Collections/Comparer.cs
src/libraries/System.Private.CoreLib/src/System/Convert.cs
src/libraries/System.Private.CoreLib/src/System/DateTime.Windows.cs
src/libraries/System.Private.CoreLib/src/System/DateTime.cs
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventProvider.cs
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/Statics.cs
src/libraries/System.Private.CoreLib/src/System/Enum.cs
src/libraries/System.Private.CoreLib/src/System/Environment.cs
src/libraries/System.Private.CoreLib/src/System/Globalization/Calendar.cs
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs
src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeFormatInfo.cs
src/libraries/System.Private.CoreLib/src/System/Globalization/HebrewCalendar.cs
src/libraries/System.Private.CoreLib/src/System/Globalization/TimeSpanParse.cs
src/libraries/System.Private.CoreLib/src/System/Guid.cs
src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/X86/Avx2.cs
src/libraries/System.Private.CoreLib/src/System/Security/SecurityElement.cs
src/libraries/System.Private.CoreLib/src/System/StringComparer.cs
src/libraries/System.Private.CoreLib/src/System/Text/UTF7Encoding.cs
src/libraries/System.Private.CoreLib/src/System/Threading/CancellationTokenSource.cs
src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs
src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TaskToApm.cs
src/libraries/System.Private.CoreLib/src/System/Tuple.cs
src/libraries/System.Private.CoreLib/src/System/ValueTuple.cs

index 75c40f0..1a71dcb 100644 (file)
@@ -452,17 +452,12 @@ namespace System
             if (!type.IsSubclassOf(typeof(Attribute)) && type != typeof(Attribute))
                 throw new ArgumentException(SR.Argument_MustHaveAttributeBaseClass);
 
-            switch (element.MemberType)
+            return element.MemberType switch
             {
-                case MemberTypes.Property:
-                    return InternalGetCustomAttributes((PropertyInfo)element, type, inherit);
-
-                case MemberTypes.Event:
-                    return InternalGetCustomAttributes((EventInfo)element, type, inherit);
-
-                default:
-                    return (element.GetCustomAttributes(type, inherit) as Attribute[])!;
-            }
+                MemberTypes.Property => InternalGetCustomAttributes((PropertyInfo)element, type, inherit),
+                MemberTypes.Event => InternalGetCustomAttributes((EventInfo)element, type, inherit),
+                _ => (element.GetCustomAttributes(type, inherit) as Attribute[])!,
+            };
         }
 
         public static Attribute[] GetCustomAttributes(MemberInfo element)
@@ -475,17 +470,12 @@ namespace System
             if (element == null)
                 throw new ArgumentNullException(nameof(element));
 
-            switch (element.MemberType)
+            return element.MemberType switch
             {
-                case MemberTypes.Property:
-                    return InternalGetCustomAttributes((PropertyInfo)element, typeof(Attribute), inherit);
-
-                case MemberTypes.Event:
-                    return InternalGetCustomAttributes((EventInfo)element, typeof(Attribute), inherit);
-
-                default:
-                    return (element.GetCustomAttributes(typeof(Attribute), inherit) as Attribute[])!;
-            }
+                MemberTypes.Property => InternalGetCustomAttributes((PropertyInfo)element, typeof(Attribute), inherit),
+                MemberTypes.Event => InternalGetCustomAttributes((EventInfo)element, typeof(Attribute), inherit),
+                _ => (element.GetCustomAttributes(typeof(Attribute), inherit) as Attribute[])!,
+            };
         }
 
         public static bool IsDefined(MemberInfo element, Type attributeType)
@@ -505,17 +495,12 @@ namespace System
             if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute))
                 throw new ArgumentException(SR.Argument_MustHaveAttributeBaseClass);
 
-            switch (element.MemberType)
+            return element.MemberType switch
             {
-                case MemberTypes.Property:
-                    return InternalIsDefined((PropertyInfo)element, attributeType, inherit);
-
-                case MemberTypes.Event:
-                    return InternalIsDefined((EventInfo)element, attributeType, inherit);
-
-                default:
-                    return element.IsDefined(attributeType, inherit);
-            }
+                MemberTypes.Property => InternalIsDefined((PropertyInfo)element, attributeType, inherit),
+                MemberTypes.Event => InternalIsDefined((EventInfo)element, attributeType, inherit),
+                _ => element.IsDefined(attributeType, inherit),
+            };
         }
 
         public static Attribute? GetCustomAttribute(MemberInfo element, Type attributeType)
index 66ceb15..24b11bb 100644 (file)
@@ -505,62 +505,27 @@ namespace System.Reflection
         #region Private Static Methods
         private static Type CustomAttributeEncodingToType(CustomAttributeEncoding encodedType)
         {
-            switch (encodedType)
-            {
-                case (CustomAttributeEncoding.Enum):
-                    return typeof(Enum);
-
-                case (CustomAttributeEncoding.Int32):
-                    return typeof(int);
-
-                case (CustomAttributeEncoding.String):
-                    return typeof(string);
-
-                case (CustomAttributeEncoding.Type):
-                    return typeof(Type);
-
-                case (CustomAttributeEncoding.Array):
-                    return typeof(Array);
-
-                case (CustomAttributeEncoding.Char):
-                    return typeof(char);
-
-                case (CustomAttributeEncoding.Boolean):
-                    return typeof(bool);
-
-                case (CustomAttributeEncoding.SByte):
-                    return typeof(sbyte);
-
-                case (CustomAttributeEncoding.Byte):
-                    return typeof(byte);
-
-                case (CustomAttributeEncoding.Int16):
-                    return typeof(short);
-
-                case (CustomAttributeEncoding.UInt16):
-                    return typeof(ushort);
-
-                case (CustomAttributeEncoding.UInt32):
-                    return typeof(uint);
-
-                case (CustomAttributeEncoding.Int64):
-                    return typeof(long);
-
-                case (CustomAttributeEncoding.UInt64):
-                    return typeof(ulong);
-
-                case (CustomAttributeEncoding.Float):
-                    return typeof(float);
-
-                case (CustomAttributeEncoding.Double):
-                    return typeof(double);
-
-                case (CustomAttributeEncoding.Object):
-                    return typeof(object);
-
-                default:
-                    throw new ArgumentException(SR.Format(SR.Arg_EnumIllegalVal, (int)encodedType), nameof(encodedType));
-            }
+            return encodedType switch
+            {
+                CustomAttributeEncoding.Enum => typeof(Enum),
+                CustomAttributeEncoding.Int32 => typeof(int),
+                CustomAttributeEncoding.String => typeof(string),
+                CustomAttributeEncoding.Type => typeof(Type),
+                CustomAttributeEncoding.Array => typeof(Array),
+                CustomAttributeEncoding.Char => typeof(char),
+                CustomAttributeEncoding.Boolean => typeof(bool),
+                CustomAttributeEncoding.SByte => typeof(sbyte),
+                CustomAttributeEncoding.Byte => typeof(byte),
+                CustomAttributeEncoding.Int16 => typeof(short),
+                CustomAttributeEncoding.UInt16 => typeof(ushort),
+                CustomAttributeEncoding.UInt32 => typeof(uint),
+                CustomAttributeEncoding.Int64 => typeof(long),
+                CustomAttributeEncoding.UInt64 => typeof(ulong),
+                CustomAttributeEncoding.Float => typeof(float),
+                CustomAttributeEncoding.Double => typeof(double),
+                CustomAttributeEncoding.Object => typeof(object),
+                _ => throw new ArgumentException(SR.Format(SR.Arg_EnumIllegalVal, (int)encodedType), nameof(encodedType)),
+            };
         }
 
         private static object EncodedValueToRawValue(long val, CustomAttributeEncoding encodedType)
index 0fa1b38..144aa32 100644 (file)
@@ -111,64 +111,25 @@ namespace System.Reflection
             }
             else
             {
-                switch (corElementType)
+                return corElementType switch
                 {
-                    #region Switch
-
-                    case CorElementType.ELEMENT_TYPE_VOID:
-                        return DBNull.Value;
-
-                    case CorElementType.ELEMENT_TYPE_CHAR:
-                        return *(char*)&buffer;
-
-                    case CorElementType.ELEMENT_TYPE_I1:
-                        return *(sbyte*)&buffer;
-
-                    case CorElementType.ELEMENT_TYPE_U1:
-                        return *(byte*)&buffer;
-
-                    case CorElementType.ELEMENT_TYPE_I2:
-                        return *(short*)&buffer;
-
-                    case CorElementType.ELEMENT_TYPE_U2:
-                        return *(ushort*)&buffer;
-
-                    case CorElementType.ELEMENT_TYPE_I4:
-                        return *(int*)&buffer;
-
-                    case CorElementType.ELEMENT_TYPE_U4:
-                        return *(uint*)&buffer;
-
-                    case CorElementType.ELEMENT_TYPE_I8:
-                        return buffer;
-
-                    case CorElementType.ELEMENT_TYPE_U8:
-                        return (ulong)buffer;
-
-                    case CorElementType.ELEMENT_TYPE_BOOLEAN:
-                        // The boolean value returned from the metadata engine is stored as a
-                        // BOOL, which actually maps to an int. We need to read it out as an int
-                        // to avoid problems on big-endian machines.
-                        return (*(int*)&buffer != 0);
-
-                    case CorElementType.ELEMENT_TYPE_R4:
-                        return *(float*)&buffer;
-
-                    case CorElementType.ELEMENT_TYPE_R8:
-                        return *(double*)&buffer;
-
-                    case CorElementType.ELEMENT_TYPE_STRING:
-                        // A string constant can be empty but never null.
-                        // A nullref constant can only be type CorElementType.ELEMENT_TYPE_CLASS.
-                        return stringVal == null ? string.Empty : stringVal;
-
-                    case CorElementType.ELEMENT_TYPE_CLASS:
-                        return null;
-
-                    default:
-                        throw new FormatException(SR.Arg_BadLiteralFormat);
-                        #endregion
-                }
+                    CorElementType.ELEMENT_TYPE_VOID => DBNull.Value,
+                    CorElementType.ELEMENT_TYPE_CHAR => *(char*)&buffer,
+                    CorElementType.ELEMENT_TYPE_I1 => *(sbyte*)&buffer,
+                    CorElementType.ELEMENT_TYPE_U1 => *(byte*)&buffer,
+                    CorElementType.ELEMENT_TYPE_I2 => *(short*)&buffer,
+                    CorElementType.ELEMENT_TYPE_U2 => *(ushort*)&buffer,
+                    CorElementType.ELEMENT_TYPE_I4 => *(int*)&buffer,
+                    CorElementType.ELEMENT_TYPE_U4 => *(uint*)&buffer,
+                    CorElementType.ELEMENT_TYPE_I8 => buffer,
+                    CorElementType.ELEMENT_TYPE_U8 => (ulong)buffer,
+                    CorElementType.ELEMENT_TYPE_BOOLEAN => (*(int*)&buffer != 0),
+                    CorElementType.ELEMENT_TYPE_R4 => *(float*)&buffer,
+                    CorElementType.ELEMENT_TYPE_R8 => *(double*)&buffer,
+                    CorElementType.ELEMENT_TYPE_STRING => stringVal == null ? string.Empty : stringVal,
+                    CorElementType.ELEMENT_TYPE_CLASS => null,
+                    _ => throw new FormatException(SR.Arg_BadLiteralFormat),
+                };
             }
         }
     }
index f4cee24..8200665 100644 (file)
@@ -31,12 +31,9 @@ namespace System.Reflection
         #region Internal Members
         internal override bool CacheEquals(object? o)
         {
-            MdFieldInfo? m = o as MdFieldInfo;
-
-            if (m is null)
-                return false;
-
-            return m.m_tkField == m_tkField &&
+            return
+                o is MdFieldInfo m &&
+                m.m_tkField == m_tkField &&
                 m_declaringType.GetTypeHandleInternal().GetModuleHandle().Equals(
                     m.m_declaringType.GetTypeHandleInternal().GetModuleHandle());
         }
index 2f45c78..cb844cd 100644 (file)
@@ -110,12 +110,7 @@ namespace System.Reflection
 
         internal override bool CacheEquals(object? o)
         {
-            RtFieldInfo? m = o as RtFieldInfo;
-
-            if (m is null)
-                return false;
-
-            return m.m_fieldHandle == m_fieldHandle;
+            return o is RtFieldInfo m && m.m_fieldHandle == m_fieldHandle;
         }
 
         #endregion
index 004933a..9a82142 100644 (file)
@@ -97,12 +97,7 @@ namespace System.Reflection
 
         internal override bool CacheEquals(object? o)
         {
-            RuntimeConstructorInfo? m = o as RuntimeConstructorInfo;
-
-            if (m is null)
-                return false;
-
-            return m.m_handle == m_handle;
+            return o is RuntimeConstructorInfo m && m.m_handle == m_handle;
         }
 
         private Signature Signature
index 20c50fb..ad85883 100644 (file)
@@ -56,12 +56,9 @@ namespace System.Reflection
         #region Internal Members
         internal override bool CacheEquals(object? o)
         {
-            RuntimeEventInfo? m = o as RuntimeEventInfo;
-
-            if (m is null)
-                return false;
-
-            return m.m_token == m_token &&
+            return
+                o is RuntimeEventInfo m &&
+                m.m_token == m_token &&
                 RuntimeTypeHandle.GetModule(m_declaringType).Equals(
                     RuntimeTypeHandle.GetModule(m.m_declaringType));
         }
index 465a6db..58707a1 100644 (file)
@@ -127,12 +127,7 @@ namespace System.Reflection
         #region Internal Members
         internal override bool CacheEquals(object? o)
         {
-            RuntimeMethodInfo? m = o as RuntimeMethodInfo;
-
-            if (m is null)
-                return false;
-
-            return m.m_handle == m_handle;
+            return o is RuntimeMethodInfo m && m.m_handle == m_handle;
         }
 
         internal Signature Signature
index 96e2fb3..0febe69 100644 (file)
@@ -55,12 +55,9 @@ namespace System.Reflection
         #region Internal Members
         internal override bool CacheEquals(object? o)
         {
-            RuntimePropertyInfo? m = o as RuntimePropertyInfo;
-
-            if (m is null)
-                return false;
-
-            return m.m_token == m_token &&
+            return
+                o is RuntimePropertyInfo m &&
+                m.m_token == m_token &&
                 RuntimeTypeHandle.GetModule(m_declaringType).Equals(
                     RuntimeTypeHandle.GetModule(m.m_declaringType));
         }
index 5e8b378..7f09a1f 100644 (file)
@@ -3131,8 +3131,7 @@ namespace System
         // Reflexive, symmetric, transitive.
         public override bool IsEquivalentTo(Type? other)
         {
-            var otherRtType = other as RuntimeType;
-            if (otherRtType is null)
+            if (!(other is RuntimeType otherRtType))
             {
                 return false;
             }
@@ -4098,8 +4097,7 @@ namespace System
         internal object CreateInstanceDefaultCtor(bool publicOnly, bool skipCheckThis, bool fillCache, bool wrapExceptions)
         {
             // Call the cached
-            ActivatorCache? cacheEntry = GenericCache as ActivatorCache;
-            if (cacheEntry != null)
+            if (GenericCache is ActivatorCache cacheEntry)
             {
                 cacheEntry.EnsureInitialized();
 
index f7ce565..8357d7e 100644 (file)
@@ -1130,15 +1130,12 @@ namespace System.StubHelpers
             }
             else
             {
-                string? strValue;
-                StringBuilder? sbValue;
-
-                if ((strValue = pManagedHome as string) != null)
+                if (pManagedHome is string strValue)
                 {
                     // string (LPStr or LPWStr)
                     pNativeHome = ConvertStringToNative(strValue, dwFlags);
                 }
-                else if ((sbValue = pManagedHome as StringBuilder) != null)
+                else if (pManagedHome is StringBuilder sbValue)
                 {
                     // StringBuilder (LPStr or LPWStr)
                     pNativeHome = ConvertStringBuilderToNative(sbValue, dwFlags);
index 334bdc8..8784037 100644 (file)
@@ -383,100 +383,43 @@ namespace System
         // managed variants as an intermediate type.
         internal static void MarshalHelperConvertObjectToVariant(object o, ref Variant v)
         {
-            IConvertible? ic = o as IConvertible;
-
             if (o == null)
             {
                 v = Empty;
             }
-            else if (ic == null)
+            else if (o is IConvertible ic)
+            {
+                IFormatProvider provider = CultureInfo.InvariantCulture;
+                v = ic.GetTypeCode() switch
+                {
+                    TypeCode.Empty => Empty,
+                    TypeCode.Object => new Variant((object)o),
+                    TypeCode.DBNull => DBNull,
+                    TypeCode.Boolean => new Variant(ic.ToBoolean(provider)),
+                    TypeCode.Char => new Variant(ic.ToChar(provider)),
+                    TypeCode.SByte => new Variant(ic.ToSByte(provider)),
+                    TypeCode.Byte => new Variant(ic.ToByte(provider)),
+                    TypeCode.Int16 => new Variant(ic.ToInt16(provider)),
+                    TypeCode.UInt16 => new Variant(ic.ToUInt16(provider)),
+                    TypeCode.Int32 => new Variant(ic.ToInt32(provider)),
+                    TypeCode.UInt32 => new Variant(ic.ToUInt32(provider)),
+                    TypeCode.Int64 => new Variant(ic.ToInt64(provider)),
+                    TypeCode.UInt64 => new Variant(ic.ToUInt64(provider)),
+                    TypeCode.Single => new Variant(ic.ToSingle(provider)),
+                    TypeCode.Double => new Variant(ic.ToDouble(provider)),
+                    TypeCode.Decimal => new Variant(ic.ToDecimal(provider)),
+                    TypeCode.DateTime => new Variant(ic.ToDateTime(provider)),
+                    TypeCode.String => new Variant(ic.ToString(provider)),
+                    _ => throw new NotSupportedException(SR.Format(SR.NotSupported_UnknownTypeCode, ic.GetTypeCode())),
+                };
+            }
+            else
             {
                 // This path should eventually go away. But until
                 // the work is done to have all of our wrapper types implement
                 // IConvertible, this is a cheapo way to get the work done.
                 v = new Variant(o);
             }
-            else
-            {
-                IFormatProvider provider = CultureInfo.InvariantCulture;
-                switch (ic.GetTypeCode())
-                {
-                    case TypeCode.Empty:
-                        v = Empty;
-                        break;
-
-                    case TypeCode.Object:
-                        v = new Variant((object)o);
-                        break;
-
-                    case TypeCode.DBNull:
-                        v = DBNull;
-                        break;
-
-                    case TypeCode.Boolean:
-                        v = new Variant(ic.ToBoolean(provider));
-                        break;
-
-                    case TypeCode.Char:
-                        v = new Variant(ic.ToChar(provider));
-                        break;
-
-                    case TypeCode.SByte:
-                        v = new Variant(ic.ToSByte(provider));
-                        break;
-
-                    case TypeCode.Byte:
-                        v = new Variant(ic.ToByte(provider));
-                        break;
-
-                    case TypeCode.Int16:
-                        v = new Variant(ic.ToInt16(provider));
-                        break;
-
-                    case TypeCode.UInt16:
-                        v = new Variant(ic.ToUInt16(provider));
-                        break;
-
-                    case TypeCode.Int32:
-                        v = new Variant(ic.ToInt32(provider));
-                        break;
-
-                    case TypeCode.UInt32:
-                        v = new Variant(ic.ToUInt32(provider));
-                        break;
-
-                    case TypeCode.Int64:
-                        v = new Variant(ic.ToInt64(provider));
-                        break;
-
-                    case TypeCode.UInt64:
-                        v = new Variant(ic.ToUInt64(provider));
-                        break;
-
-                    case TypeCode.Single:
-                        v = new Variant(ic.ToSingle(provider));
-                        break;
-
-                    case TypeCode.Double:
-                        v = new Variant(ic.ToDouble(provider));
-                        break;
-
-                    case TypeCode.Decimal:
-                        v = new Variant(ic.ToDecimal(provider));
-                        break;
-
-                    case TypeCode.DateTime:
-                        v = new Variant(ic.ToDateTime(provider));
-                        break;
-
-                    case TypeCode.String:
-                        v = new Variant(ic.ToString(provider));
-                        break;
-
-                    default:
-                        throw new NotSupportedException(SR.Format(SR.NotSupported_UnknownTypeCode, ic.GetTypeCode()));
-                }
-            }
         }
 
         // Helper code for marshaling VARIANTS to managed objects (we use
@@ -530,106 +473,34 @@ namespace System
             else
             {
                 IFormatProvider provider = CultureInfo.InvariantCulture;
-                switch (vt)
+                v = vt switch
                 {
-                    case 0: /*VT_EMPTY*/
-                        v = Empty;
-                        break;
-
-                    case 1: /*VT_NULL*/
-                        v = DBNull;
-                        break;
-
-                    case 2: /*VT_I2*/
-                        v = new Variant(iv.ToInt16(provider));
-                        break;
-
-                    case 3: /*VT_I4*/
-                        v = new Variant(iv.ToInt32(provider));
-                        break;
-
-                    case 4: /*VT_R4*/
-                        v = new Variant(iv.ToSingle(provider));
-                        break;
-
-                    case 5: /*VT_R8*/
-                        v = new Variant(iv.ToDouble(provider));
-                        break;
-
-                    case 6: /*VT_CY*/
-                        v = new Variant(new CurrencyWrapper(iv.ToDecimal(provider)));
-                        break;
-
-                    case 7: /*VT_DATE*/
-                        v = new Variant(iv.ToDateTime(provider));
-                        break;
-
-                    case 8: /*VT_BSTR*/
-                        v = new Variant(iv.ToString(provider));
-                        break;
-
-                    case 9: /*VT_DISPATCH*/
-                        v = new Variant(new DispatchWrapper((object)iv));
-                        break;
-
-                    case 10: /*VT_ERROR*/
-                        v = new Variant(new ErrorWrapper(iv.ToInt32(provider)));
-                        break;
-
-                    case 11: /*VT_BOOL*/
-                        v = new Variant(iv.ToBoolean(provider));
-                        break;
-
-                    case 12: /*VT_VARIANT*/
-                        v = new Variant((object)iv);
-                        break;
-
-                    case 13: /*VT_UNKNOWN*/
-                        v = new Variant(new UnknownWrapper((object)iv));
-                        break;
-
-                    case 14: /*VT_DECIMAL*/
-                        v = new Variant(iv.ToDecimal(provider));
-                        break;
-
-                    // case 15: /*unused*/
-                    //  NOT SUPPORTED
-
-                    case 16: /*VT_I1*/
-                        v = new Variant(iv.ToSByte(provider));
-                        break;
-
-                    case 17: /*VT_UI1*/
-                        v = new Variant(iv.ToByte(provider));
-                        break;
-
-                    case 18: /*VT_UI2*/
-                        v = new Variant(iv.ToUInt16(provider));
-                        break;
-
-                    case 19: /*VT_UI4*/
-                        v = new Variant(iv.ToUInt32(provider));
-                        break;
-
-                    case 20: /*VT_I8*/
-                        v = new Variant(iv.ToInt64(provider));
-                        break;
-
-                    case 21: /*VT_UI8*/
-                        v = new Variant(iv.ToUInt64(provider));
-                        break;
-
-                    case 22: /*VT_INT*/
-                        v = new Variant(iv.ToInt32(provider));
-                        break;
-
-                    case 23: /*VT_UINT*/
-                        v = new Variant(iv.ToUInt32(provider));
-                        break;
-
-                    default:
-                        throw new InvalidCastException(SR.InvalidCast_CannotCoerceByRefVariant);
-                }
+                    0 => /*VT_EMPTY*/ Empty,
+                    1 => /*VT_NULL*/ DBNull,
+                    2 => /*VT_I2*/ new Variant(iv.ToInt16(provider)),
+                    3 => /*VT_I4*/ new Variant(iv.ToInt32(provider)),
+                    4 => /*VT_R4*/ new Variant(iv.ToSingle(provider)),
+                    5 => /*VT_R8*/ new Variant(iv.ToDouble(provider)),
+                    6 => /*VT_CY*/ new Variant(new CurrencyWrapper(iv.ToDecimal(provider))),
+                    7 => /*VT_DATE*/ new Variant(iv.ToDateTime(provider)),
+                    8 => /*VT_BSTR*/ new Variant(iv.ToString(provider)),
+                    9 => /*VT_DISPATCH*/ new Variant(new DispatchWrapper((object)iv)),
+                    10 => /*VT_ERROR*/ new Variant(new ErrorWrapper(iv.ToInt32(provider))),
+                    11 => /*VT_BOOL*/ new Variant(iv.ToBoolean(provider)),
+                    12 => /*VT_VARIANT*/ new Variant((object)iv),
+                    13 => /*VT_UNKNOWN*/ new Variant(new UnknownWrapper((object)iv)),
+                    14 => /*VT_DECIMAL*/ new Variant(iv.ToDecimal(provider)),
+                    // 15 => : /*unused*/ NOT SUPPORTED
+                    16 => /*VT_I1*/ new Variant(iv.ToSByte(provider)),
+                    17 => /*VT_UI1*/ new Variant(iv.ToByte(provider)),
+                    18 => /*VT_UI2*/ new Variant(iv.ToUInt16(provider)),
+                    19 => /*VT_UI4*/ new Variant(iv.ToUInt32(provider)),
+                    20 => /*VT_I8*/ new Variant(iv.ToInt64(provider)),
+                    21 => /*VT_UI8*/ new Variant(iv.ToUInt64(provider)),
+                    22 => /*VT_INT*/ new Variant(iv.ToInt32(provider)),
+                    23 => /*VT_UINT*/ new Variant(iv.ToUInt32(provider)),
+                    _ => throw new InvalidCastException(SR.InvalidCast_CannotCoerceByRefVariant),
+                };
             }
         }
     }
index e0f079f..85277d9 100644 (file)
@@ -258,7 +258,7 @@ namespace System
             }
 
             Exception[]? innerExceptions = info.GetValue("InnerExceptions", typeof(Exception[])) as Exception[];
-            if (innerExceptions == null)
+            if (innerExceptions is null)
             {
                 throw new SerializationException(SR.AggregateException_DeserializationFailure);
             }
index 247b1ea..5a338c3 100644 (file)
@@ -936,9 +936,8 @@ namespace System
                 return retVal;
 #endif
 
-            object[]? objArray = array as object[];
             int endIndex = startIndex + count;
-            if (objArray != null)
+            if (array is object[] objArray)
             {
                 if (value == null)
                 {
@@ -1120,9 +1119,8 @@ namespace System
                 return retVal;
 #endif
 
-            object[]? objArray = array as object[];
             int endIndex = startIndex - count + 1;
-            if (objArray != null)
+            if (array is object[] objArray)
             {
                 if (value == null)
                 {
index 74d6076..122c490 100644 (file)
@@ -105,23 +105,14 @@ namespace System.Buffers.Text
                 offset = value.Offset;
             }
 
-            switch (symbol)
+            return symbol switch
             {
-                case 'R':
-                    return TryFormatDateTimeR(value.UtcDateTime, destination, out bytesWritten);
-
-                case 'l':
-                    return TryFormatDateTimeL(value.UtcDateTime, destination, out bytesWritten);
-
-                case 'O':
-                    return TryFormatDateTimeO(value.DateTime, value.Offset, destination, out bytesWritten);
-
-                case 'G':
-                    return TryFormatDateTimeG(value.DateTime, offset, destination, out bytesWritten);
-
-                default:
-                    return FormattingHelpers.TryFormatThrowFormatException(out bytesWritten);
-            }
+                'R' => TryFormatDateTimeR(value.UtcDateTime, destination, out bytesWritten),
+                'l' => TryFormatDateTimeL(value.UtcDateTime, destination, out bytesWritten),
+                'O' => TryFormatDateTimeO(value.DateTime, value.Offset, destination, out bytesWritten),
+                'G' => TryFormatDateTimeG(value.DateTime, offset, destination, out bytesWritten),
+                _ => FormattingHelpers.TryFormatThrowFormatException(out bytesWritten),
+            };
         }
 
         /// <summary>
@@ -149,23 +140,14 @@ namespace System.Buffers.Text
         {
             char symbol = FormattingHelpers.GetSymbolOrDefault(format, 'G');
 
-            switch (symbol)
+            return symbol switch
             {
-                case 'R':
-                    return TryFormatDateTimeR(value, destination, out bytesWritten);
-
-                case 'l':
-                    return TryFormatDateTimeL(value, destination, out bytesWritten);
-
-                case 'O':
-                    return TryFormatDateTimeO(value, Utf8Constants.NullUtcOffset, destination, out bytesWritten);
-
-                case 'G':
-                    return TryFormatDateTimeG(value, Utf8Constants.NullUtcOffset, destination, out bytesWritten);
-
-                default:
-                    return FormattingHelpers.TryFormatThrowFormatException(out bytesWritten);
-            }
+                'R' => TryFormatDateTimeR(value, destination, out bytesWritten),
+                'l' => TryFormatDateTimeL(value, destination, out bytesWritten),
+                'O' => TryFormatDateTimeO(value, Utf8Constants.NullUtcOffset, destination, out bytesWritten),
+                'G' => TryFormatDateTimeG(value, Utf8Constants.NullUtcOffset, destination, out bytesWritten),
+                _ => FormattingHelpers.TryFormatThrowFormatException(out bytesWritten),
+            };
         }
     }
 }
index 1672185..7fb6f0c 100644 (file)
@@ -121,26 +121,15 @@ namespace System.Buffers.Text
         /// </exceptions>
         public static bool TryParse(ReadOnlySpan<byte> source, out DateTimeOffset value, out int bytesConsumed, char standardFormat = default)
         {
-            switch (standardFormat)
+            return standardFormat switch
             {
-                case 'R':
-                    return TryParseDateTimeOffsetR(source, NoFlipCase, out value, out bytesConsumed);
-
-                case 'l':
-                    return TryParseDateTimeOffsetR(source, FlipCase, out value, out bytesConsumed);
-
-                case 'O':
-                    return TryParseDateTimeOffsetO(source, out value, out bytesConsumed, out _);
-
-                case default(char):
-                    return TryParseDateTimeOffsetDefault(source, out value, out bytesConsumed);
-
-                case 'G':
-                    return TryParseDateTimeG(source, out DateTime _, out value, out bytesConsumed);
-
-                default:
-                    return ParserHelpers.TryParseThrowFormatException(out value, out bytesConsumed);
-            }
+                'R' => TryParseDateTimeOffsetR(source, NoFlipCase, out value, out bytesConsumed),
+                'l' => TryParseDateTimeOffsetR(source, FlipCase, out value, out bytesConsumed),
+                'O' => TryParseDateTimeOffsetO(source, out value, out bytesConsumed, out _),
+                default(char) => TryParseDateTimeOffsetDefault(source, out value, out bytesConsumed),
+                'G' => TryParseDateTimeG(source, out DateTime _, out value, out bytesConsumed),
+                _ => ParserHelpers.TryParseThrowFormatException(out value, out bytesConsumed),
+            };
         }
 
         private const uint FlipCase = 0x00000020u;  // XOR mask to flip the case of a letter.
index d4ae3da..52bc99f 100644 (file)
@@ -983,8 +983,7 @@ namespace System.Collections
 
                 if (c.Count > 0)
                 {
-                    ArrayList? al = _list as ArrayList;
-                    if (al != null)
+                    if (_list is ArrayList al)
                     {
                         // We need to special case ArrayList.
                         // When c is a range of _list, we need to handle this in a special way.
index e8f431b..102d2c9 100644 (file)
@@ -58,8 +58,7 @@ namespace System.Collections
             if (a == null) return -1;
             if (b == null) return 1;
 
-            string? sa = a as string;
-            if (sa != null && b is string sb)
+            if (a is string sa && b is string sb)
                 return _compareInfo.Compare(sa, sb);
 
             if (a is IComparable ia)
index 8616cd9..e9c230c 100644 (file)
@@ -208,47 +208,28 @@ namespace System
             // This line is invalid for things like Enums that return a TypeCode
             // of int, but the object can't actually be cast to an int.
             //            if (v.GetTypeCode() == typeCode) return value;
-            switch (typeCode)
+            return typeCode switch
             {
-                case TypeCode.Boolean:
-                    return v.ToBoolean(provider);
-                case TypeCode.Char:
-                    return v.ToChar(provider);
-                case TypeCode.SByte:
-                    return v.ToSByte(provider);
-                case TypeCode.Byte:
-                    return v.ToByte(provider);
-                case TypeCode.Int16:
-                    return v.ToInt16(provider);
-                case TypeCode.UInt16:
-                    return v.ToUInt16(provider);
-                case TypeCode.Int32:
-                    return v.ToInt32(provider);
-                case TypeCode.UInt32:
-                    return v.ToUInt32(provider);
-                case TypeCode.Int64:
-                    return v.ToInt64(provider);
-                case TypeCode.UInt64:
-                    return v.ToUInt64(provider);
-                case TypeCode.Single:
-                    return v.ToSingle(provider);
-                case TypeCode.Double:
-                    return v.ToDouble(provider);
-                case TypeCode.Decimal:
-                    return v.ToDecimal(provider);
-                case TypeCode.DateTime:
-                    return v.ToDateTime(provider);
-                case TypeCode.String:
-                    return v.ToString(provider);
-                case TypeCode.Object:
-                    return value;
-                case TypeCode.DBNull:
-                    throw new InvalidCastException(SR.InvalidCast_DBNull);
-                case TypeCode.Empty:
-                    throw new InvalidCastException(SR.InvalidCast_Empty);
-                default:
-                    throw new ArgumentException(SR.Arg_UnknownTypeCode);
-            }
+                TypeCode.Boolean => v.ToBoolean(provider),
+                TypeCode.Char => v.ToChar(provider),
+                TypeCode.SByte => v.ToSByte(provider),
+                TypeCode.Byte => v.ToByte(provider),
+                TypeCode.Int16 => v.ToInt16(provider),
+                TypeCode.UInt16 => v.ToUInt16(provider),
+                TypeCode.Int32 => v.ToInt32(provider),
+                TypeCode.UInt32 => v.ToUInt32(provider),
+                TypeCode.Int64 => v.ToInt64(provider),
+                TypeCode.UInt64 => v.ToUInt64(provider),
+                TypeCode.Single => v.ToSingle(provider),
+                TypeCode.Double => v.ToDouble(provider),
+                TypeCode.Decimal => v.ToDecimal(provider),
+                TypeCode.DateTime => v.ToDateTime(provider),
+                TypeCode.String => v.ToString(provider),
+                TypeCode.Object => value,
+                TypeCode.DBNull => throw new InvalidCastException(SR.InvalidCast_DBNull),
+                TypeCode.Empty => throw new InvalidCastException(SR.InvalidCast_Empty),
+                _ => throw new ArgumentException(SR.Arg_UnknownTypeCode),
+            };
         }
 
         internal static object DefaultToType(IConvertible value, Type targetType, IFormatProvider? provider)
index 468c369..ebfed3c 100644 (file)
@@ -31,13 +31,12 @@ namespace System
             DateTime dt = new DateTime(year, month, day);
             FullSystemTime time = new FullSystemTime(year, month, dt.DayOfWeek, day, hour, minute, second);
 
-            switch (kind)
+            return kind switch
             {
-                case DateTimeKind.Local: return ValidateSystemTime(&time.systemTime, localTime: true);
-                case DateTimeKind.Utc:   return ValidateSystemTime(&time.systemTime, localTime: false);
-                default:
-                    return ValidateSystemTime(&time.systemTime, localTime: true) || ValidateSystemTime(&time.systemTime, localTime: false);
-            }
+                DateTimeKind.Local => ValidateSystemTime(&time.systemTime, localTime: true),
+                DateTimeKind.Utc => ValidateSystemTime(&time.systemTime, localTime: false),
+                _ => ValidateSystemTime(&time.systemTime, localTime: true) || ValidateSystemTime(&time.systemTime, localTime: false),
+            };
         }
 
         private static unsafe DateTime FromFileTimeLeapSecondsAware(long fileTime)
index 4bdbaf0..6cb1c1e 100644 (file)
@@ -1061,15 +1061,12 @@ namespace System
         {
             get
             {
-                switch (InternalKind)
+                return InternalKind switch
                 {
-                    case KindUnspecified:
-                        return DateTimeKind.Unspecified;
-                    case KindUtc:
-                        return DateTimeKind.Utc;
-                    default:
-                        return DateTimeKind.Local;
-                }
+                    KindUnspecified => DateTimeKind.Unspecified,
+                    KindUtc => DateTimeKind.Utc,
+                    _ => DateTimeKind.Local,
+                };
             }
         }
 
index 8460b8b..4b22fc0 100644 (file)
@@ -134,25 +134,15 @@ namespace System.Diagnostics.Tracing
         // EventSource has special logic to do this, no one else should be calling EventProvider.
         internal EventProvider(EventProviderType providerType)
         {
-            switch (providerType)
+            m_eventProvider = providerType switch
             {
-                case EventProviderType.ETW:
 #if PLATFORM_WINDOWS
-                    m_eventProvider = new EtwEventProvider();
-#else
-                    m_eventProvider = new NoOpEventProvider();
+                EventProviderType.ETW => new EtwEventProvider(),
 #endif
-                    break;
-                case EventProviderType.EventPipe:
 #if FEATURE_PERFTRACING
-                    m_eventProvider = new EventPipeEventProvider();
-#else
-                    m_eventProvider = new NoOpEventProvider();
+                EventProviderType.EventPipe => new EventPipeEventProvider(),
 #endif
-                    break;
-                default:
-                    m_eventProvider = new NoOpEventProvider();
-                    break;
+                _ => new NoOpEventProvider(),
             };
         }
 
index 0131a00..e32b3b8 100644 (file)
@@ -203,25 +203,18 @@ namespace System.Diagnostics.Tracing
             EventFieldFormat format,
             TraceLoggingDataType native)
         {
-            switch (format)
+            return format switch
             {
-                case EventFieldFormat.Default:
-                    return native;
-                case EventFieldFormat.String:
-                    return TraceLoggingDataType.Char8;
-                case EventFieldFormat.Boolean:
-                    return TraceLoggingDataType.Boolean8;
-                case EventFieldFormat.Hexadecimal:
-                    return TraceLoggingDataType.HexInt8;
+                EventFieldFormat.Default => native,
+                EventFieldFormat.String => TraceLoggingDataType.Char8,
+                EventFieldFormat.Boolean => TraceLoggingDataType.Boolean8,
+                EventFieldFormat.Hexadecimal => TraceLoggingDataType.HexInt8,
 #if false
-                case EventSourceFieldFormat.Signed:
-                    return TraceLoggingDataType.Int8;
-                case EventSourceFieldFormat.Unsigned:
-                    return TraceLoggingDataType.UInt8;
+                EventSourceFieldFormat.Signed => TraceLoggingDataType.Int8,
+                EventSourceFieldFormat.Unsigned => TraceLoggingDataType.UInt8,
 #endif
-                default:
-                    return MakeDataType(native, format);
-            }
+                _ => MakeDataType(native, format),
+            };
         }
 
         /// <summary>
@@ -234,25 +227,18 @@ namespace System.Diagnostics.Tracing
             EventFieldFormat format,
             TraceLoggingDataType native)
         {
-            switch (format)
+            return format switch
             {
-                case EventFieldFormat.Default:
-                    return native;
-                case EventFieldFormat.String:
-                    return TraceLoggingDataType.Char16;
-                case EventFieldFormat.Hexadecimal:
-                    return TraceLoggingDataType.HexInt16;
+                EventFieldFormat.Default => native,
+                EventFieldFormat.String => TraceLoggingDataType.Char16,
+                EventFieldFormat.Hexadecimal => TraceLoggingDataType.HexInt16,
 #if false
-                case EventSourceFieldFormat.Port:
-                    return TraceLoggingDataType.Port;
-                case EventSourceFieldFormat.Signed:
-                    return TraceLoggingDataType.Int16;
-                case EventSourceFieldFormat.Unsigned:
-                    return TraceLoggingDataType.UInt16;
+                EventSourceFieldFormat.Port => TraceLoggingDataType.Port,
+                EventSourceFieldFormat.Signed => TraceLoggingDataType.Int16,
+                EventSourceFieldFormat.Unsigned => TraceLoggingDataType.UInt16,
 #endif
-                default:
-                    return MakeDataType(native, format);
-            }
+                _ => MakeDataType(native, format),
+            };
         }
 
         /// <summary>
@@ -265,37 +251,27 @@ namespace System.Diagnostics.Tracing
             EventFieldFormat format,
             TraceLoggingDataType native)
         {
-            switch (format)
+            return format switch
             {
-                case EventFieldFormat.Default:
-                    return native;
-                case EventFieldFormat.Boolean:
-                    return TraceLoggingDataType.Boolean32;
-                case EventFieldFormat.Hexadecimal:
-                    return TraceLoggingDataType.HexInt32;
+                EventFieldFormat.Default => native,
+                EventFieldFormat.Boolean => TraceLoggingDataType.Boolean32,
+                EventFieldFormat.Hexadecimal => TraceLoggingDataType.HexInt32,
 #if false
-                case EventSourceFieldFormat.Ipv4Address:
-                    return TraceLoggingDataType.Ipv4Address;
-                case EventSourceFieldFormat.ProcessId:
-                    return TraceLoggingDataType.ProcessId;
-                case EventSourceFieldFormat.ThreadId:
-                    return TraceLoggingDataType.ThreadId;
-                case EventSourceFieldFormat.Win32Error:
-                    return TraceLoggingDataType.Win32Error;
-                case EventSourceFieldFormat.NTStatus:
-                    return TraceLoggingDataType.NTStatus;
+                EventSourceFieldFormat.Ipv4Address => TraceLoggingDataType.Ipv4Address,
+                EventSourceFieldFormat.ProcessId => TraceLoggingDataType.ProcessId,
+                EventSourceFieldFormat.ThreadId => TraceLoggingDataType.ThreadId,
+                EventSourceFieldFormat.Win32Error => TraceLoggingDataType.Win32Error,
+                EventSourceFieldFormat.NTStatus => TraceLoggingDataType.NTStatus,
 #endif
-                case EventFieldFormat.HResult:
-                    return TraceLoggingDataType.HResult;
+                EventFieldFormat.HResult => TraceLoggingDataType.HResult,
 #if false
                 case EventSourceFieldFormat.Signed:
                     return TraceLoggingDataType.Int32;
                 case EventSourceFieldFormat.Unsigned:
                     return TraceLoggingDataType.UInt32;
 #endif
-                default:
-                    return MakeDataType(native, format);
-            }
+                _ => MakeDataType(native, format),
+            };
         }
 
         /// <summary>
@@ -308,23 +284,17 @@ namespace System.Diagnostics.Tracing
             EventFieldFormat format,
             TraceLoggingDataType native)
         {
-            switch (format)
+            return format switch
             {
-                case EventFieldFormat.Default:
-                    return native;
-                case EventFieldFormat.Hexadecimal:
-                    return TraceLoggingDataType.HexInt64;
+                EventFieldFormat.Default => native,
+                EventFieldFormat.Hexadecimal => TraceLoggingDataType.HexInt64,
 #if false
-                case EventSourceFieldFormat.FileTime:
-                    return TraceLoggingDataType.FileTime;
-                case EventSourceFieldFormat.Signed:
-                    return TraceLoggingDataType.Int64;
-                case EventSourceFieldFormat.Unsigned:
-                    return TraceLoggingDataType.UInt64;
+                EventSourceFieldFormat.FileTime => TraceLoggingDataType.FileTime,
+                EventSourceFieldFormat.Signed => TraceLoggingDataType.Int64,
+                EventSourceFieldFormat.Unsigned => TraceLoggingDataType.UInt64,
 #endif
-                default:
-                    return MakeDataType(native, format);
-            }
+                _ => MakeDataType(native, format),
+            };
         }
 
         /// <summary>
@@ -337,21 +307,16 @@ namespace System.Diagnostics.Tracing
             EventFieldFormat format,
             TraceLoggingDataType native)
         {
-            switch (format)
+            return format switch
             {
-                case EventFieldFormat.Default:
-                    return native;
-                case EventFieldFormat.Hexadecimal:
-                    return HexIntPtrType;
+                EventFieldFormat.Default => native,
+                EventFieldFormat.Hexadecimal => HexIntPtrType,
 #if false
-                case EventSourceFieldFormat.Signed:
-                    return IntPtrType;
-                case EventSourceFieldFormat.Unsigned:
-                    return UIntPtrType;
+                EventSourceFieldFormat.Signed => IntPtrType,
+                EventSourceFieldFormat.Unsigned => UIntPtrType,
 #endif
-                default:
-                    return MakeDataType(native, format);
-            }
+                _ => MakeDataType(native, format),
+            };
         }
 
         #endregion
index df7c1ee..206b1e3 100644 (file)
@@ -42,39 +42,24 @@ namespace System
         private string ValueToString()
         {
             ref byte data = ref this.GetRawData();
-            switch (InternalGetCorElementType())
+            return (InternalGetCorElementType()) switch
             {
-                case CorElementType.ELEMENT_TYPE_I1:
-                    return Unsafe.As<byte, sbyte>(ref data).ToString();
-                case CorElementType.ELEMENT_TYPE_U1:
-                    return data.ToString();
-                case CorElementType.ELEMENT_TYPE_BOOLEAN:
-                    return Unsafe.As<byte, bool>(ref data).ToString();
-                case CorElementType.ELEMENT_TYPE_I2:
-                    return Unsafe.As<byte, short>(ref data).ToString();
-                case CorElementType.ELEMENT_TYPE_U2:
-                    return Unsafe.As<byte, ushort>(ref data).ToString();
-                case CorElementType.ELEMENT_TYPE_CHAR:
-                    return Unsafe.As<byte, char>(ref data).ToString();
-                case CorElementType.ELEMENT_TYPE_I4:
-                    return Unsafe.As<byte, int>(ref data).ToString();
-                case CorElementType.ELEMENT_TYPE_U4:
-                    return Unsafe.As<byte, uint>(ref data).ToString();
-                case CorElementType.ELEMENT_TYPE_R4:
-                    return Unsafe.As<byte, float>(ref data).ToString();
-                case CorElementType.ELEMENT_TYPE_I8:
-                    return Unsafe.As<byte, long>(ref data).ToString();
-                case CorElementType.ELEMENT_TYPE_U8:
-                    return Unsafe.As<byte, ulong>(ref data).ToString();
-                case CorElementType.ELEMENT_TYPE_R8:
-                    return Unsafe.As<byte, double>(ref data).ToString();
-                case CorElementType.ELEMENT_TYPE_I:
-                    return Unsafe.As<byte, IntPtr>(ref data).ToString();
-                case CorElementType.ELEMENT_TYPE_U:
-                    return Unsafe.As<byte, UIntPtr>(ref data).ToString();
-                default:
-                    throw new InvalidOperationException(SR.InvalidOperation_UnknownEnumType);
-            }
+                CorElementType.ELEMENT_TYPE_I1 => Unsafe.As<byte, sbyte>(ref data).ToString(),
+                CorElementType.ELEMENT_TYPE_U1 => data.ToString(),
+                CorElementType.ELEMENT_TYPE_BOOLEAN => Unsafe.As<byte, bool>(ref data).ToString(),
+                CorElementType.ELEMENT_TYPE_I2 => Unsafe.As<byte, short>(ref data).ToString(),
+                CorElementType.ELEMENT_TYPE_U2 => Unsafe.As<byte, ushort>(ref data).ToString(),
+                CorElementType.ELEMENT_TYPE_CHAR => Unsafe.As<byte, char>(ref data).ToString(),
+                CorElementType.ELEMENT_TYPE_I4 => Unsafe.As<byte, int>(ref data).ToString(),
+                CorElementType.ELEMENT_TYPE_U4 => Unsafe.As<byte, uint>(ref data).ToString(),
+                CorElementType.ELEMENT_TYPE_R4 => Unsafe.As<byte, float>(ref data).ToString(),
+                CorElementType.ELEMENT_TYPE_I8 => Unsafe.As<byte, long>(ref data).ToString(),
+                CorElementType.ELEMENT_TYPE_U8 => Unsafe.As<byte, ulong>(ref data).ToString(),
+                CorElementType.ELEMENT_TYPE_R8 => Unsafe.As<byte, double>(ref data).ToString(),
+                CorElementType.ELEMENT_TYPE_I => Unsafe.As<byte, IntPtr>(ref data).ToString(),
+                CorElementType.ELEMENT_TYPE_U => Unsafe.As<byte, UIntPtr>(ref data).ToString(),
+                _ => throw new InvalidOperationException(SR.InvalidOperation_UnknownEnumType),
+            };
         }
 
         private string ValueToHexString()
@@ -104,33 +89,20 @@ namespace System
 
         private static string ValueToHexString(object value)
         {
-            switch (Convert.GetTypeCode(value))
+            return (Convert.GetTypeCode(value)) switch
             {
-                case TypeCode.SByte:
-                    return ((byte)(sbyte)value).ToString("X2", null);
-                case TypeCode.Byte:
-                    return ((byte)value).ToString("X2", null);
-                case TypeCode.Boolean:
-                    // direct cast from bool to byte is not allowed
-                    return Convert.ToByte((bool)value).ToString("X2", null);
-                case TypeCode.Int16:
-                    return ((ushort)(short)value).ToString("X4", null);
-                case TypeCode.UInt16:
-                    return ((ushort)value).ToString("X4", null);
-                case TypeCode.Char:
-                    return ((ushort)(char)value).ToString("X4", null);
-                case TypeCode.UInt32:
-                    return ((uint)value).ToString("X8", null);
-                case TypeCode.Int32:
-                    return ((uint)(int)value).ToString("X8", null);
-                case TypeCode.UInt64:
-                    return ((ulong)value).ToString("X16", null);
-                case TypeCode.Int64:
-                    return ((ulong)(long)value).ToString("X16", null);
-                // All unsigned types will be directly cast
-                default:
-                    throw new InvalidOperationException(SR.InvalidOperation_UnknownEnumType);
-            }
+                TypeCode.SByte => ((byte)(sbyte)value).ToString("X2", null),
+                TypeCode.Byte => ((byte)value).ToString("X2", null),
+                TypeCode.Boolean => Convert.ToByte((bool)value).ToString("X2", null), // direct cast from bool to byte is not allowed
+                TypeCode.Int16 => ((ushort)(short)value).ToString("X4", null),
+                TypeCode.UInt16 => ((ushort)value).ToString("X4", null),
+                TypeCode.Char => ((ushort)(char)value).ToString("X4", null),
+                TypeCode.UInt32 => ((uint)value).ToString("X8", null),
+                TypeCode.Int32 => ((uint)(int)value).ToString("X8", null),
+                TypeCode.UInt64 => ((ulong)value).ToString("X16", null),
+                TypeCode.Int64 => ((ulong)(long)value).ToString("X16", null),
+                _ => throw new InvalidOperationException(SR.InvalidOperation_UnknownEnumType),
+            };
         }
 
         internal static string? GetEnumName(RuntimeType enumType, ulong ulValue)
@@ -271,46 +243,20 @@ namespace System
             // Helper function to silently convert the value to UInt64 from the other base types for enum without throwing an exception.
             // This is need since the Convert functions do overflow checks.
             TypeCode typeCode = Convert.GetTypeCode(value);
-
-            ulong result;
-            switch (typeCode)
+            var result = typeCode switch
             {
-                case TypeCode.SByte:
-                    result = (ulong)(sbyte)value;
-                    break;
-                case TypeCode.Byte:
-                    result = (byte)value;
-                    break;
-                case TypeCode.Boolean:
-                    // direct cast from bool to byte is not allowed
-                    result = Convert.ToByte((bool)value);
-                    break;
-                case TypeCode.Int16:
-                    result = (ulong)(short)value;
-                    break;
-                case TypeCode.UInt16:
-                    result = (ushort)value;
-                    break;
-                case TypeCode.Char:
-                    result = (ushort)(char)value;
-                    break;
-                case TypeCode.UInt32:
-                    result = (uint)value;
-                    break;
-                case TypeCode.Int32:
-                    result = (ulong)(int)value;
-                    break;
-                case TypeCode.UInt64:
-                    result = (ulong)value;
-                    break;
-                case TypeCode.Int64:
-                    result = (ulong)(long)value;
-                    break;
-                // All unsigned types will be directly cast
-                default:
-                    throw new InvalidOperationException(SR.InvalidOperation_UnknownEnumType);
-            }
-
+                TypeCode.SByte => (ulong)(sbyte)value,
+                TypeCode.Byte => (byte)value,
+                TypeCode.Boolean => Convert.ToByte((bool)value), // direct cast from bool to byte is not allowed
+                TypeCode.Int16 => (ulong)(short)value,
+                TypeCode.UInt16 => (ushort)value,
+                TypeCode.Char => (ushort)(char)value,
+                TypeCode.UInt32 => (uint)value,
+                TypeCode.Int32 => (ulong)(int)value,
+                TypeCode.UInt64 => (ulong)value,
+                TypeCode.Int64 => (ulong)(long)value,
+                _ => throw new InvalidOperationException(SR.InvalidOperation_UnknownEnumType),
+            };
             return result;
         }
 
@@ -786,42 +732,20 @@ namespace System
             // Delegate rest of error checking to the other functions
             TypeCode typeCode = Convert.GetTypeCode(value);
 
-            switch (typeCode)
+            return typeCode switch
             {
-                case TypeCode.Int32:
-                    return ToObject(enumType, (int)value);
-
-                case TypeCode.SByte:
-                    return ToObject(enumType, (sbyte)value);
-
-                case TypeCode.Int16:
-                    return ToObject(enumType, (short)value);
-
-                case TypeCode.Int64:
-                    return ToObject(enumType, (long)value);
-
-                case TypeCode.UInt32:
-                    return ToObject(enumType, (uint)value);
-
-                case TypeCode.Byte:
-                    return ToObject(enumType, (byte)value);
-
-                case TypeCode.UInt16:
-                    return ToObject(enumType, (ushort)value);
-
-                case TypeCode.UInt64:
-                    return ToObject(enumType, (ulong)value);
-
-                case TypeCode.Char:
-                    return ToObject(enumType, (char)value);
-
-                case TypeCode.Boolean:
-                    return ToObject(enumType, (bool)value);
-
-                default:
-                    // All unsigned types will be directly cast
-                    throw new ArgumentException(SR.Arg_MustBeEnumBaseTypeOrEnum, nameof(value));
-            }
+                TypeCode.Int32 => ToObject(enumType, (int)value),
+                TypeCode.SByte => ToObject(enumType, (sbyte)value),
+                TypeCode.Int16 => ToObject(enumType, (short)value),
+                TypeCode.Int64 => ToObject(enumType, (long)value),
+                TypeCode.UInt32 => ToObject(enumType, (uint)value),
+                TypeCode.Byte => ToObject(enumType, (byte)value),
+                TypeCode.UInt16 => ToObject(enumType, (ushort)value),
+                TypeCode.UInt64 => ToObject(enumType, (ulong)value),
+                TypeCode.Char => ToObject(enumType, (char)value),
+                TypeCode.Boolean => ToObject(enumType, (bool)value),
+                _ => throw new ArgumentException(SR.Arg_MustBeEnumBaseTypeOrEnum, nameof(value)),
+            };
         }
 
         public static string Format(Type enumType, object value, string format)
@@ -886,39 +810,24 @@ namespace System
         internal object GetValue()
         {
             ref byte data = ref this.GetRawData();
-            switch (InternalGetCorElementType())
+            return (InternalGetCorElementType()) switch
             {
-                case CorElementType.ELEMENT_TYPE_I1:
-                    return Unsafe.As<byte, sbyte>(ref data);
-                case CorElementType.ELEMENT_TYPE_U1:
-                    return data;
-                case CorElementType.ELEMENT_TYPE_BOOLEAN:
-                    return Unsafe.As<byte, bool>(ref data);
-                case CorElementType.ELEMENT_TYPE_I2:
-                    return Unsafe.As<byte, short>(ref data);
-                case CorElementType.ELEMENT_TYPE_U2:
-                    return Unsafe.As<byte, ushort>(ref data);
-                case CorElementType.ELEMENT_TYPE_CHAR:
-                    return Unsafe.As<byte, char>(ref data);
-                case CorElementType.ELEMENT_TYPE_I4:
-                    return Unsafe.As<byte, int>(ref data);
-                case CorElementType.ELEMENT_TYPE_U4:
-                    return Unsafe.As<byte, uint>(ref data);
-                case CorElementType.ELEMENT_TYPE_R4:
-                    return Unsafe.As<byte, float>(ref data);
-                case CorElementType.ELEMENT_TYPE_I8:
-                    return Unsafe.As<byte, long>(ref data);
-                case CorElementType.ELEMENT_TYPE_U8:
-                    return Unsafe.As<byte, ulong>(ref data);
-                case CorElementType.ELEMENT_TYPE_R8:
-                    return Unsafe.As<byte, double>(ref data);
-                case CorElementType.ELEMENT_TYPE_I:
-                    return Unsafe.As<byte, IntPtr>(ref data);
-                case CorElementType.ELEMENT_TYPE_U:
-                    return Unsafe.As<byte, UIntPtr>(ref data);
-                default:
-                    throw new InvalidOperationException(SR.InvalidOperation_UnknownEnumType);
-            }
+                CorElementType.ELEMENT_TYPE_I1 => Unsafe.As<byte, sbyte>(ref data),
+                CorElementType.ELEMENT_TYPE_U1 => data,
+                CorElementType.ELEMENT_TYPE_BOOLEAN => Unsafe.As<byte, bool>(ref data),
+                CorElementType.ELEMENT_TYPE_I2 => Unsafe.As<byte, short>(ref data),
+                CorElementType.ELEMENT_TYPE_U2 => Unsafe.As<byte, ushort>(ref data),
+                CorElementType.ELEMENT_TYPE_CHAR => Unsafe.As<byte, char>(ref data),
+                CorElementType.ELEMENT_TYPE_I4 => Unsafe.As<byte, int>(ref data),
+                CorElementType.ELEMENT_TYPE_U4 => Unsafe.As<byte, uint>(ref data),
+                CorElementType.ELEMENT_TYPE_R4 => Unsafe.As<byte, float>(ref data),
+                CorElementType.ELEMENT_TYPE_I8 => Unsafe.As<byte, long>(ref data),
+                CorElementType.ELEMENT_TYPE_U8 => Unsafe.As<byte, ulong>(ref data),
+                CorElementType.ELEMENT_TYPE_R8 => Unsafe.As<byte, double>(ref data),
+                CorElementType.ELEMENT_TYPE_I => Unsafe.As<byte, IntPtr>(ref data),
+                CorElementType.ELEMENT_TYPE_U => Unsafe.As<byte, UIntPtr>(ref data),
+                _ => throw new InvalidOperationException(SR.InvalidOperation_UnknownEnumType),
+            };
         }
 
         private ulong ToUInt64()
@@ -966,39 +875,24 @@ namespace System
             // The runtime can bypass calls to Enum::GetHashCode and call the underlying type's GetHashCode directly
             // to avoid boxing the enum.
             ref byte data = ref this.GetRawData();
-            switch (InternalGetCorElementType())
+            return (InternalGetCorElementType()) switch
             {
-                case CorElementType.ELEMENT_TYPE_I1:
-                    return Unsafe.As<byte, sbyte>(ref data).GetHashCode();
-                case CorElementType.ELEMENT_TYPE_U1:
-                    return data.GetHashCode();
-                case CorElementType.ELEMENT_TYPE_BOOLEAN:
-                    return Unsafe.As<byte, bool>(ref data).GetHashCode();
-                case CorElementType.ELEMENT_TYPE_I2:
-                    return Unsafe.As<byte, short>(ref data).GetHashCode();
-                case CorElementType.ELEMENT_TYPE_U2:
-                    return Unsafe.As<byte, ushort>(ref data).GetHashCode();
-                case CorElementType.ELEMENT_TYPE_CHAR:
-                    return Unsafe.As<byte, char>(ref data).GetHashCode();
-                case CorElementType.ELEMENT_TYPE_I4:
-                    return Unsafe.As<byte, int>(ref data).GetHashCode();
-                case CorElementType.ELEMENT_TYPE_U4:
-                    return Unsafe.As<byte, uint>(ref data).GetHashCode();
-                case CorElementType.ELEMENT_TYPE_R4:
-                    return Unsafe.As<byte, float>(ref data).GetHashCode();
-                case CorElementType.ELEMENT_TYPE_I8:
-                    return Unsafe.As<byte, long>(ref data).GetHashCode();
-                case CorElementType.ELEMENT_TYPE_U8:
-                    return Unsafe.As<byte, ulong>(ref data).GetHashCode();
-                case CorElementType.ELEMENT_TYPE_R8:
-                    return Unsafe.As<byte, double>(ref data).GetHashCode();
-                case CorElementType.ELEMENT_TYPE_I:
-                    return Unsafe.As<byte, IntPtr>(ref data).GetHashCode();
-                case CorElementType.ELEMENT_TYPE_U:
-                    return Unsafe.As<byte, UIntPtr>(ref data).GetHashCode();
-                default:
-                    throw new InvalidOperationException(SR.InvalidOperation_UnknownEnumType);
-            }
+                CorElementType.ELEMENT_TYPE_I1 => Unsafe.As<byte, sbyte>(ref data).GetHashCode(),
+                CorElementType.ELEMENT_TYPE_U1 => data.GetHashCode(),
+                CorElementType.ELEMENT_TYPE_BOOLEAN => Unsafe.As<byte, bool>(ref data).GetHashCode(),
+                CorElementType.ELEMENT_TYPE_I2 => Unsafe.As<byte, short>(ref data).GetHashCode(),
+                CorElementType.ELEMENT_TYPE_U2 => Unsafe.As<byte, ushort>(ref data).GetHashCode(),
+                CorElementType.ELEMENT_TYPE_CHAR => Unsafe.As<byte, char>(ref data).GetHashCode(),
+                CorElementType.ELEMENT_TYPE_I4 => Unsafe.As<byte, int>(ref data).GetHashCode(),
+                CorElementType.ELEMENT_TYPE_U4 => Unsafe.As<byte, uint>(ref data).GetHashCode(),
+                CorElementType.ELEMENT_TYPE_R4 => Unsafe.As<byte, float>(ref data).GetHashCode(),
+                CorElementType.ELEMENT_TYPE_I8 => Unsafe.As<byte, long>(ref data).GetHashCode(),
+                CorElementType.ELEMENT_TYPE_U8 => Unsafe.As<byte, ulong>(ref data).GetHashCode(),
+                CorElementType.ELEMENT_TYPE_R8 => Unsafe.As<byte, double>(ref data).GetHashCode(),
+                CorElementType.ELEMENT_TYPE_I => Unsafe.As<byte, IntPtr>(ref data).GetHashCode(),
+                CorElementType.ELEMENT_TYPE_U => Unsafe.As<byte, UIntPtr>(ref data).GetHashCode(),
+                _ => throw new InvalidOperationException(SR.InvalidOperation_UnknownEnumType),
+            };
         }
 
         public override string ToString()
@@ -1066,31 +960,20 @@ namespace System
         #region IConvertible
         public TypeCode GetTypeCode()
         {
-            switch (InternalGetCorElementType())
+            return (InternalGetCorElementType()) switch
             {
-                case CorElementType.ELEMENT_TYPE_I1:
-                    return TypeCode.SByte;
-                case CorElementType.ELEMENT_TYPE_U1:
-                    return TypeCode.Byte;
-                case CorElementType.ELEMENT_TYPE_BOOLEAN:
-                    return TypeCode.Boolean;
-                case CorElementType.ELEMENT_TYPE_I2:
-                    return TypeCode.Int16;
-                case CorElementType.ELEMENT_TYPE_U2:
-                    return TypeCode.UInt16;
-                case CorElementType.ELEMENT_TYPE_CHAR:
-                    return TypeCode.Char;
-                case CorElementType.ELEMENT_TYPE_I4:
-                    return TypeCode.Int32;
-                case CorElementType.ELEMENT_TYPE_U4:
-                    return TypeCode.UInt32;
-                case CorElementType.ELEMENT_TYPE_I8:
-                    return TypeCode.Int64;
-                case CorElementType.ELEMENT_TYPE_U8:
-                    return TypeCode.UInt64;
-                default:
-                    throw new InvalidOperationException(SR.InvalidOperation_UnknownEnumType);
-            }
+                CorElementType.ELEMENT_TYPE_I1 => TypeCode.SByte,
+                CorElementType.ELEMENT_TYPE_U1 => TypeCode.Byte,
+                CorElementType.ELEMENT_TYPE_BOOLEAN => TypeCode.Boolean,
+                CorElementType.ELEMENT_TYPE_I2 => TypeCode.Int16,
+                CorElementType.ELEMENT_TYPE_U2 => TypeCode.UInt16,
+                CorElementType.ELEMENT_TYPE_CHAR => TypeCode.Char,
+                CorElementType.ELEMENT_TYPE_I4 => TypeCode.Int32,
+                CorElementType.ELEMENT_TYPE_U4 => TypeCode.UInt32,
+                CorElementType.ELEMENT_TYPE_I8 => TypeCode.Int64,
+                CorElementType.ELEMENT_TYPE_U8 => TypeCode.UInt64,
+                _ => throw new InvalidOperationException(SR.InvalidOperation_UnknownEnumType),
+            };
         }
 
         bool IConvertible.ToBoolean(IFormatProvider? provider)
index 2b638fd..0f60203 100644 (file)
@@ -162,8 +162,7 @@ namespace System
                 // present in Process.  If it proves important, we could look at separating that functionality out of Process into
                 // Common files which could also be included here.
                 Type? processType = Type.GetType("System.Diagnostics.Process, System.Diagnostics.Process, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", throwOnError: false);
-                IDisposable? currentProcess = processType?.GetMethod("GetCurrentProcess")?.Invoke(null, BindingFlags.DoNotWrapExceptions, null, null, null) as IDisposable;
-                if (currentProcess != null)
+                if (processType?.GetMethod("GetCurrentProcess")?.Invoke(null, BindingFlags.DoNotWrapExceptions, null, null, null) is IDisposable currentProcess)
                 {
                     using (currentProcess)
                     {
index 4460d3d..86e6301 100644 (file)
@@ -520,19 +520,17 @@ namespace System.Globalization
                     firstDayOfWeek,
                     SR.Format(SR.ArgumentOutOfRange_Range, DayOfWeek.Sunday, DayOfWeek.Saturday));
             }
-            switch (rule)
+
+            return rule switch
             {
-                case CalendarWeekRule.FirstDay:
-                    return GetFirstDayWeekOfYear(time, (int)firstDayOfWeek);
-                case CalendarWeekRule.FirstFullWeek:
-                    return GetWeekOfYearFullDays(time, (int)firstDayOfWeek, 7);
-                case CalendarWeekRule.FirstFourDayWeek:
-                    return GetWeekOfYearFullDays(time, (int)firstDayOfWeek, 4);
-                default:
-                    throw new ArgumentOutOfRangeException(
+                CalendarWeekRule.FirstDay => GetFirstDayWeekOfYear(time, (int)firstDayOfWeek),
+                CalendarWeekRule.FirstFullWeek => GetWeekOfYearFullDays(time, (int)firstDayOfWeek, 7),
+                CalendarWeekRule.FirstFourDayWeek => GetWeekOfYearFullDays(time, (int)firstDayOfWeek, 4),
+                _ => throw new ArgumentOutOfRangeException(
                         nameof(rule),
                         rule,
-                        SR.Format(SR.ArgumentOutOfRange_Range, CalendarWeekRule.FirstDay, CalendarWeekRule.FirstFourDayWeek));            }
+                        SR.Format(SR.ArgumentOutOfRange_Range, CalendarWeekRule.FirstDay, CalendarWeekRule.FirstFourDayWeek)),
+            };
         }
 
         /// <summary>
index 63dd62c..76ddc4c 100644 (file)
@@ -649,15 +649,12 @@ namespace System.Globalization
             get
             {
                 // special case the compatibility cultures
-                switch (this.Name)
+                return Name switch
                 {
-                    case "zh-CHT":
-                        return "zh-Hant";
-                    case "zh-CHS":
-                        return "zh-Hans";
-                    default:
-                        return this.Name;
-                }
+                    "zh-CHT" => "zh-Hant",
+                    "zh-CHS" => "zh-Hans",
+                    _ => Name,
+                };
             }
         }
 
index 67a7b47..07327ff 100644 (file)
@@ -1316,19 +1316,12 @@ namespace System.Globalization
         /// </summary>
         internal string InternalGetMonthName(int month, MonthNameStyles style, bool abbreviated)
         {
-            string[] monthNamesArray;
-            switch (style)
+            string[] monthNamesArray = style switch
             {
-                case MonthNameStyles.Genitive:
-                    monthNamesArray = InternalGetGenitiveMonthNames(abbreviated);
-                    break;
-                case MonthNameStyles.LeapYear:
-                    monthNamesArray = InternalGetLeapYearMonthNames();
-                    break;
-                default:
-                    monthNamesArray = (abbreviated ? InternalGetAbbreviatedMonthNames() : InternalGetMonthNames());
-                    break;
-            }
+                MonthNameStyles.Genitive => InternalGetGenitiveMonthNames(abbreviated),
+                MonthNameStyles.LeapYear => InternalGetLeapYearMonthNames(),
+                _ => (abbreviated ? InternalGetAbbreviatedMonthNames() : InternalGetMonthNames()),
+            };
 
             // The month range is from 1 ~ m_monthNames.Length
             // (actually is 13 right now for all cases)
index d72e381..667721d 100644 (file)
@@ -363,17 +363,13 @@ namespace System.Globalization
 
         private static int GetResult(DateBuffer result, int part)
         {
-            switch (part)
+            return part switch
             {
-                case DatePartYear:
-                    return result.year;
-                case DatePartMonth:
-                    return result.month;
-                case DatePartDay:
-                    return result.day;
-            }
-
-            throw new InvalidOperationException(SR.InvalidOperation_DateTimeParsing);
+                DatePartYear => result.year,
+                DatePartMonth => result.month,
+                DatePartDay => result.day,
+                _ => throw new InvalidOperationException(SR.InvalidOperation_DateTimeParsing),
+            };
         }
 
         /// <summary>
index 7dfac05..4f492b7 100644 (file)
@@ -568,18 +568,18 @@ namespace System.Globalization
 
         internal static long Pow10(int pow)
         {
-            switch (pow)
-            {
-                case 0:  return 1;
-                case 1:  return 10;
-                case 2:  return 100;
-                case 3:  return 1000;
-                case 4:  return 10000;
-                case 5:  return 100000;
-                case 6:  return 1000000;
-                case 7:  return 10000000;
-                default: return (long)Math.Pow(10, pow);
-            }
+            return pow switch
+            {
+                0 => 1,
+                1 => 10,
+                2 => 100,
+                3 => 1000,
+                4 => 10000,
+                5 => 100000,
+                6 => 1000000,
+                7 => 10000000,
+                _ => (long)Math.Pow(10, pow),
+            };
         }
 
         private static bool TryTimeToTicks(bool positive, TimeSpanToken days, TimeSpanToken hours, TimeSpanToken minutes, TimeSpanToken seconds, TimeSpanToken fraction, out long result)
@@ -740,15 +740,15 @@ namespace System.Globalization
                 }
             }
 
-            switch (raw._numCount)
+            return raw._numCount switch
             {
-                case 1: return ProcessTerminal_D(ref raw, style, ref result);
-                case 2: return ProcessTerminal_HM(ref raw, style, ref result);
-                case 3: return ProcessTerminal_HM_S_D(ref raw, style, ref result);
-                case 4: return ProcessTerminal_HMS_F_D(ref raw, style, ref result);
-                case 5: return ProcessTerminal_DHMSF(ref raw, style, ref result);
-                default: return result.SetBadTimeSpanFailure();
-            }
+                1 => ProcessTerminal_D(ref raw, style, ref result),
+                2 => ProcessTerminal_HM(ref raw, style, ref result),
+                3 => ProcessTerminal_HM_S_D(ref raw, style, ref result),
+                4 => ProcessTerminal_HMS_F_D(ref raw, style, ref result),
+                5 => ProcessTerminal_DHMSF(ref raw, style, ref result),
+                _ => result.SetBadTimeSpanFailure(),
+            };
         }
 
         /// <summary>Validate the 5-number "Days.Hours:Minutes:Seconds.Fraction" terminal case.</summary>
index ba92c19..1a9aee7 100644 (file)
@@ -238,33 +238,15 @@ namespace System
             input = input.Trim();
 
             var result = new GuidResult(GuidParseThrowStyle.AllButOverflow);
-            bool success;
-            switch ((char)(format[0] | 0x20))
-            {
-                case 'd':
-                    success = TryParseExactD(input, ref result);
-                    break;
-
-                case 'n':
-                    success = TryParseExactN(input, ref result);
-                    break;
-
-                case 'b':
-                    success = TryParseExactB(input, ref result);
-                    break;
-
-                case 'p':
-                    success = TryParseExactP(input, ref result);
-                    break;
-
-                case 'x':
-                    success = TryParseExactX(input, ref result);
-                    break;
-
-                default:
-                    throw new FormatException(SR.Format_InvalidGuidFormatSpecification);
-            }
-
+            bool success = ((char)(format[0] | 0x20)) switch
+            {
+                'd' => TryParseExactD(input, ref result),
+                'n' => TryParseExactN(input, ref result),
+                'b' => TryParseExactB(input, ref result),
+                'p' => TryParseExactP(input, ref result),
+                'x' => TryParseExactX(input, ref result),
+                _ => throw new FormatException(SR.Format_InvalidGuidFormatSpecification),
+            };
             Debug.Assert(success, "GuidParseThrowStyle.AllButOverflow means throw on all failures");
             return result._parsedGuid;
         }
@@ -337,21 +319,16 @@ namespace System
                 return false;
             }
 
-            switch (guidString[0])
+            return (guidString[0]) switch
             {
-                case '(':
-                    return TryParseExactP(guidString, ref result);
-
-                case '{':
-                    return guidString.Contains('-') ?
+                '(' => TryParseExactP(guidString, ref result),
+                '{' => guidString.Contains('-') ?
                         TryParseExactB(guidString, ref result) :
-                        TryParseExactX(guidString, ref result);
-
-                default:
-                    return guidString.Contains('-') ?
+                        TryParseExactX(guidString, ref result),
+                _ => guidString.Contains('-') ?
                         TryParseExactD(guidString, ref result) :
-                        TryParseExactN(guidString, ref result);
-            }
+                        TryParseExactN(guidString, ref result),
+            };
         }
 
         // Two helpers used for parsing components:
index 3a066bb..f3e5877 100644 (file)
@@ -848,19 +848,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector128<int> GatherVector128(int* baseAddress, Vector128<int> index, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherVector128(baseAddress, index, 1);
-                case 2:
-                    return GatherVector128(baseAddress, index, 2);
-                case 4:
-                    return GatherVector128(baseAddress, index, 4);
-                case 8:
-                    return GatherVector128(baseAddress, index, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherVector128(baseAddress, index, 1),
+                2 => GatherVector128(baseAddress, index, 2),
+                4 => GatherVector128(baseAddress, index, 4),
+                8 => GatherVector128(baseAddress, index, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m128i _mm_i32gather_epi32 (int const* base_addr, __m128i vindex, const int scale)
@@ -869,19 +864,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector128<uint> GatherVector128(uint* baseAddress, Vector128<int> index, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherVector128(baseAddress, index, 1);
-                case 2:
-                    return GatherVector128(baseAddress, index, 2);
-                case 4:
-                    return GatherVector128(baseAddress, index, 4);
-                case 8:
-                    return GatherVector128(baseAddress, index, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherVector128(baseAddress, index, 1),
+                2 => GatherVector128(baseAddress, index, 2),
+                4 => GatherVector128(baseAddress, index, 4),
+                8 => GatherVector128(baseAddress, index, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m128i _mm_i32gather_epi64 (__int64 const* base_addr, __m128i vindex, const int scale)
@@ -890,19 +880,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector128<long> GatherVector128(long* baseAddress, Vector128<int> index, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherVector128(baseAddress, index, 1);
-                case 2:
-                    return GatherVector128(baseAddress, index, 2);
-                case 4:
-                    return GatherVector128(baseAddress, index, 4);
-                case 8:
-                    return GatherVector128(baseAddress, index, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherVector128(baseAddress, index, 1),
+                2 => GatherVector128(baseAddress, index, 2),
+                4 => GatherVector128(baseAddress, index, 4),
+                8 => GatherVector128(baseAddress, index, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m128i _mm_i32gather_epi64 (__int64 const* base_addr, __m128i vindex, const int scale)
@@ -911,19 +896,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector128<ulong> GatherVector128(ulong* baseAddress, Vector128<int> index, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherVector128(baseAddress, index, 1);
-                case 2:
-                    return GatherVector128(baseAddress, index, 2);
-                case 4:
-                    return GatherVector128(baseAddress, index, 4);
-                case 8:
-                    return GatherVector128(baseAddress, index, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherVector128(baseAddress, index, 1),
+                2 => GatherVector128(baseAddress, index, 2),
+                4 => GatherVector128(baseAddress, index, 4),
+                8 => GatherVector128(baseAddress, index, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m128 _mm_i32gather_ps (float const* base_addr, __m128i vindex, const int scale)
@@ -932,19 +912,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector128<float> GatherVector128(float* baseAddress, Vector128<int> index, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherVector128(baseAddress, index, 1);
-                case 2:
-                    return GatherVector128(baseAddress, index, 2);
-                case 4:
-                    return GatherVector128(baseAddress, index, 4);
-                case 8:
-                    return GatherVector128(baseAddress, index, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherVector128(baseAddress, index, 1),
+                2 => GatherVector128(baseAddress, index, 2),
+                4 => GatherVector128(baseAddress, index, 4),
+                8 => GatherVector128(baseAddress, index, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m128d _mm_i32gather_pd (double const* base_addr, __m128i vindex, const int scale)
@@ -953,19 +928,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector128<double> GatherVector128(double* baseAddress, Vector128<int> index, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherVector128(baseAddress, index, 1);
-                case 2:
-                    return GatherVector128(baseAddress, index, 2);
-                case 4:
-                    return GatherVector128(baseAddress, index, 4);
-                case 8:
-                    return GatherVector128(baseAddress, index, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherVector128(baseAddress, index, 1),
+                2 => GatherVector128(baseAddress, index, 2),
+                4 => GatherVector128(baseAddress, index, 4),
+                8 => GatherVector128(baseAddress, index, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m128i _mm_i64gather_epi32 (int const* base_addr, __m128i vindex, const int scale)
@@ -974,19 +944,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector128<int> GatherVector128(int* baseAddress, Vector128<long> index, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherVector128(baseAddress, index, 1);
-                case 2:
-                    return GatherVector128(baseAddress, index, 2);
-                case 4:
-                    return GatherVector128(baseAddress, index, 4);
-                case 8:
-                    return GatherVector128(baseAddress, index, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherVector128(baseAddress, index, 1),
+                2 => GatherVector128(baseAddress, index, 2),
+                4 => GatherVector128(baseAddress, index, 4),
+                8 => GatherVector128(baseAddress, index, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m128i _mm_i64gather_epi32 (int const* base_addr, __m128i vindex, const int scale)
@@ -995,19 +960,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector128<uint> GatherVector128(uint* baseAddress, Vector128<long> index, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherVector128(baseAddress, index, 1);
-                case 2:
-                    return GatherVector128(baseAddress, index, 2);
-                case 4:
-                    return GatherVector128(baseAddress, index, 4);
-                case 8:
-                    return GatherVector128(baseAddress, index, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherVector128(baseAddress, index, 1),
+                2 => GatherVector128(baseAddress, index, 2),
+                4 => GatherVector128(baseAddress, index, 4),
+                8 => GatherVector128(baseAddress, index, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m128i _mm_i64gather_epi64 (__int64 const* base_addr, __m128i vindex, const int scale)
@@ -1016,19 +976,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector128<long> GatherVector128(long* baseAddress, Vector128<long> index, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherVector128(baseAddress, index, 1);
-                case 2:
-                    return GatherVector128(baseAddress, index, 2);
-                case 4:
-                    return GatherVector128(baseAddress, index, 4);
-                case 8:
-                    return GatherVector128(baseAddress, index, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherVector128(baseAddress, index, 1),
+                2 => GatherVector128(baseAddress, index, 2),
+                4 => GatherVector128(baseAddress, index, 4),
+                8 => GatherVector128(baseAddress, index, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m128i _mm_i64gather_epi64 (__int64 const* base_addr, __m128i vindex, const int scale)
@@ -1037,19 +992,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector128<ulong> GatherVector128(ulong* baseAddress, Vector128<long> index, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherVector128(baseAddress, index, 1);
-                case 2:
-                    return GatherVector128(baseAddress, index, 2);
-                case 4:
-                    return GatherVector128(baseAddress, index, 4);
-                case 8:
-                    return GatherVector128(baseAddress, index, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherVector128(baseAddress, index, 1),
+                2 => GatherVector128(baseAddress, index, 2),
+                4 => GatherVector128(baseAddress, index, 4),
+                8 => GatherVector128(baseAddress, index, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m128 _mm_i64gather_ps (float const* base_addr, __m128i vindex, const int scale)
@@ -1058,19 +1008,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector128<float> GatherVector128(float* baseAddress, Vector128<long> index, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherVector128(baseAddress, index, 1);
-                case 2:
-                    return GatherVector128(baseAddress, index, 2);
-                case 4:
-                    return GatherVector128(baseAddress, index, 4);
-                case 8:
-                    return GatherVector128(baseAddress, index, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherVector128(baseAddress, index, 1),
+                2 => GatherVector128(baseAddress, index, 2),
+                4 => GatherVector128(baseAddress, index, 4),
+                8 => GatherVector128(baseAddress, index, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m128d _mm_i64gather_pd (double const* base_addr, __m128i vindex, const int scale)
@@ -1079,19 +1024,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector128<double> GatherVector128(double* baseAddress, Vector128<long> index, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherVector128(baseAddress, index, 1);
-                case 2:
-                    return GatherVector128(baseAddress, index, 2);
-                case 4:
-                    return GatherVector128(baseAddress, index, 4);
-                case 8:
-                    return GatherVector128(baseAddress, index, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherVector128(baseAddress, index, 1),
+                2 => GatherVector128(baseAddress, index, 2),
+                4 => GatherVector128(baseAddress, index, 4),
+                8 => GatherVector128(baseAddress, index, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m256i _mm256_i32gather_epi32 (int const* base_addr, __m256i vindex, const int scale)
@@ -1100,19 +1040,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector256<int> GatherVector256(int* baseAddress, Vector256<int> index, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherVector256(baseAddress, index, 1);
-                case 2:
-                    return GatherVector256(baseAddress, index, 2);
-                case 4:
-                    return GatherVector256(baseAddress, index, 4);
-                case 8:
-                    return GatherVector256(baseAddress, index, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherVector256(baseAddress, index, 1),
+                2 => GatherVector256(baseAddress, index, 2),
+                4 => GatherVector256(baseAddress, index, 4),
+                8 => GatherVector256(baseAddress, index, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m256i _mm256_i32gather_epi32 (int const* base_addr, __m256i vindex, const int scale)
@@ -1121,19 +1056,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector256<uint> GatherVector256(uint* baseAddress, Vector256<int> index, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherVector256(baseAddress, index, 1);
-                case 2:
-                    return GatherVector256(baseAddress, index, 2);
-                case 4:
-                    return GatherVector256(baseAddress, index, 4);
-                case 8:
-                    return GatherVector256(baseAddress, index, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherVector256(baseAddress, index, 1),
+                2 => GatherVector256(baseAddress, index, 2),
+                4 => GatherVector256(baseAddress, index, 4),
+                8 => GatherVector256(baseAddress, index, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m256i _mm256_i32gather_epi64 (__int64 const* base_addr, __m128i vindex, const int scale)
@@ -1142,19 +1072,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector256<long> GatherVector256(long* baseAddress, Vector128<int> index, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherVector256(baseAddress, index, 1);
-                case 2:
-                    return GatherVector256(baseAddress, index, 2);
-                case 4:
-                    return GatherVector256(baseAddress, index, 4);
-                case 8:
-                    return GatherVector256(baseAddress, index, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherVector256(baseAddress, index, 1),
+                2 => GatherVector256(baseAddress, index, 2),
+                4 => GatherVector256(baseAddress, index, 4),
+                8 => GatherVector256(baseAddress, index, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m256i _mm256_i32gather_epi64 (__int64 const* base_addr, __m128i vindex, const int scale)
@@ -1163,19 +1088,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector256<ulong> GatherVector256(ulong* baseAddress, Vector128<int> index, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherVector256(baseAddress, index, 1);
-                case 2:
-                    return GatherVector256(baseAddress, index, 2);
-                case 4:
-                    return GatherVector256(baseAddress, index, 4);
-                case 8:
-                    return GatherVector256(baseAddress, index, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherVector256(baseAddress, index, 1),
+                2 => GatherVector256(baseAddress, index, 2),
+                4 => GatherVector256(baseAddress, index, 4),
+                8 => GatherVector256(baseAddress, index, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m256 _mm256_i32gather_ps (float const* base_addr, __m256i vindex, const int scale)
@@ -1184,19 +1104,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector256<float> GatherVector256(float* baseAddress, Vector256<int> index, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherVector256(baseAddress, index, 1);
-                case 2:
-                    return GatherVector256(baseAddress, index, 2);
-                case 4:
-                    return GatherVector256(baseAddress, index, 4);
-                case 8:
-                    return GatherVector256(baseAddress, index, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherVector256(baseAddress, index, 1),
+                2 => GatherVector256(baseAddress, index, 2),
+                4 => GatherVector256(baseAddress, index, 4),
+                8 => GatherVector256(baseAddress, index, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m256d _mm256_i32gather_pd (double const* base_addr, __m128i vindex, const int scale)
@@ -1205,19 +1120,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector256<double> GatherVector256(double* baseAddress, Vector128<int> index, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherVector256(baseAddress, index, 1);
-                case 2:
-                    return GatherVector256(baseAddress, index, 2);
-                case 4:
-                    return GatherVector256(baseAddress, index, 4);
-                case 8:
-                    return GatherVector256(baseAddress, index, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherVector256(baseAddress, index, 1),
+                2 => GatherVector256(baseAddress, index, 2),
+                4 => GatherVector256(baseAddress, index, 4),
+                8 => GatherVector256(baseAddress, index, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m128i _mm256_i64gather_epi32 (int const* base_addr, __m256i vindex, const int scale)
@@ -1226,19 +1136,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector128<int> GatherVector128(int* baseAddress, Vector256<long> index, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherVector128(baseAddress, index, 1);
-                case 2:
-                    return GatherVector128(baseAddress, index, 2);
-                case 4:
-                    return GatherVector128(baseAddress, index, 4);
-                case 8:
-                    return GatherVector128(baseAddress, index, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherVector128(baseAddress, index, 1),
+                2 => GatherVector128(baseAddress, index, 2),
+                4 => GatherVector128(baseAddress, index, 4),
+                8 => GatherVector128(baseAddress, index, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m128i _mm256_i64gather_epi32 (int const* base_addr, __m256i vindex, const int scale)
@@ -1247,19 +1152,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector128<uint> GatherVector128(uint* baseAddress, Vector256<long> index, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherVector128(baseAddress, index, 1);
-                case 2:
-                    return GatherVector128(baseAddress, index, 2);
-                case 4:
-                    return GatherVector128(baseAddress, index, 4);
-                case 8:
-                    return GatherVector128(baseAddress, index, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherVector128(baseAddress, index, 1),
+                2 => GatherVector128(baseAddress, index, 2),
+                4 => GatherVector128(baseAddress, index, 4),
+                8 => GatherVector128(baseAddress, index, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m256i _mm256_i64gather_epi64 (__int64 const* base_addr, __m256i vindex, const int scale)
@@ -1268,19 +1168,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector256<long> GatherVector256(long* baseAddress, Vector256<long> index, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherVector256(baseAddress, index, 1);
-                case 2:
-                    return GatherVector256(baseAddress, index, 2);
-                case 4:
-                    return GatherVector256(baseAddress, index, 4);
-                case 8:
-                    return GatherVector256(baseAddress, index, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherVector256(baseAddress, index, 1),
+                2 => GatherVector256(baseAddress, index, 2),
+                4 => GatherVector256(baseAddress, index, 4),
+                8 => GatherVector256(baseAddress, index, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m256i _mm256_i64gather_epi64 (__int64 const* base_addr, __m256i vindex, const int scale)
@@ -1289,19 +1184,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector256<ulong> GatherVector256(ulong* baseAddress, Vector256<long> index, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherVector256(baseAddress, index, 1);
-                case 2:
-                    return GatherVector256(baseAddress, index, 2);
-                case 4:
-                    return GatherVector256(baseAddress, index, 4);
-                case 8:
-                    return GatherVector256(baseAddress, index, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherVector256(baseAddress, index, 1),
+                2 => GatherVector256(baseAddress, index, 2),
+                4 => GatherVector256(baseAddress, index, 4),
+                8 => GatherVector256(baseAddress, index, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m128 _mm256_i64gather_ps (float const* base_addr, __m256i vindex, const int scale)
@@ -1310,19 +1200,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector128<float> GatherVector128(float* baseAddress, Vector256<long> index, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherVector128(baseAddress, index, 1);
-                case 2:
-                    return GatherVector128(baseAddress, index, 2);
-                case 4:
-                    return GatherVector128(baseAddress, index, 4);
-                case 8:
-                    return GatherVector128(baseAddress, index, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherVector128(baseAddress, index, 1),
+                2 => GatherVector128(baseAddress, index, 2),
+                4 => GatherVector128(baseAddress, index, 4),
+                8 => GatherVector128(baseAddress, index, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m256d _mm256_i64gather_pd (double const* base_addr, __m256i vindex, const int scale)
@@ -1331,19 +1216,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector256<double> GatherVector256(double* baseAddress, Vector256<long> index, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherVector256(baseAddress, index, 1);
-                case 2:
-                    return GatherVector256(baseAddress, index, 2);
-                case 4:
-                    return GatherVector256(baseAddress, index, 4);
-                case 8:
-                    return GatherVector256(baseAddress, index, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherVector256(baseAddress, index, 1),
+                2 => GatherVector256(baseAddress, index, 2),
+                4 => GatherVector256(baseAddress, index, 4),
+                8 => GatherVector256(baseAddress, index, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
 
         /// <summary>
@@ -1353,19 +1233,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector128<int> GatherMaskVector128(Vector128<int> source, int* baseAddress, Vector128<int> index, Vector128<int> mask, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 1);
-                case 2:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 2);
-                case 4:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 4);
-                case 8:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherMaskVector128(source, baseAddress, index, mask, 1),
+                2 => GatherMaskVector128(source, baseAddress, index, mask, 2),
+                4 => GatherMaskVector128(source, baseAddress, index, mask, 4),
+                8 => GatherMaskVector128(source, baseAddress, index, mask, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m128i _mm_mask_i32gather_epi32 (__m128i src, int const* base_addr, __m128i vindex, __m128i mask, const int scale)
@@ -1374,19 +1249,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector128<uint> GatherMaskVector128(Vector128<uint> source, uint* baseAddress, Vector128<int> index, Vector128<uint> mask, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 1);
-                case 2:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 2);
-                case 4:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 4);
-                case 8:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherMaskVector128(source, baseAddress, index, mask, 1),
+                2 => GatherMaskVector128(source, baseAddress, index, mask, 2),
+                4 => GatherMaskVector128(source, baseAddress, index, mask, 4),
+                8 => GatherMaskVector128(source, baseAddress, index, mask, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m128i _mm_mask_i32gather_epi64 (__m128i src, __int64 const* base_addr, __m128i vindex, __m128i mask, const int scale)
@@ -1395,19 +1265,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector128<long> GatherMaskVector128(Vector128<long> source, long* baseAddress, Vector128<int> index, Vector128<long> mask, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 1);
-                case 2:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 2);
-                case 4:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 4);
-                case 8:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherMaskVector128(source, baseAddress, index, mask, 1),
+                2 => GatherMaskVector128(source, baseAddress, index, mask, 2),
+                4 => GatherMaskVector128(source, baseAddress, index, mask, 4),
+                8 => GatherMaskVector128(source, baseAddress, index, mask, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m128i _mm_mask_i32gather_epi64 (__m128i src, __int64 const* base_addr, __m128i vindex, __m128i mask, const int scale)
@@ -1416,19 +1281,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector128<ulong> GatherMaskVector128(Vector128<ulong> source, ulong* baseAddress, Vector128<int> index, Vector128<ulong> mask, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 1);
-                case 2:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 2);
-                case 4:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 4);
-                case 8:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherMaskVector128(source, baseAddress, index, mask, 1),
+                2 => GatherMaskVector128(source, baseAddress, index, mask, 2),
+                4 => GatherMaskVector128(source, baseAddress, index, mask, 4),
+                8 => GatherMaskVector128(source, baseAddress, index, mask, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m128 _mm_mask_i32gather_ps (__m128 src, float const* base_addr, __m128i vindex, __m128 mask, const int scale)
@@ -1437,19 +1297,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector128<float> GatherMaskVector128(Vector128<float> source, float* baseAddress, Vector128<int> index, Vector128<float> mask, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 1);
-                case 2:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 2);
-                case 4:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 4);
-                case 8:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherMaskVector128(source, baseAddress, index, mask, 1),
+                2 => GatherMaskVector128(source, baseAddress, index, mask, 2),
+                4 => GatherMaskVector128(source, baseAddress, index, mask, 4),
+                8 => GatherMaskVector128(source, baseAddress, index, mask, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m128d _mm_mask_i32gather_pd (__m128d src, double const* base_addr, __m128i vindex, __m128d mask, const int scale)
@@ -1458,19 +1313,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector128<double> GatherMaskVector128(Vector128<double> source, double* baseAddress, Vector128<int> index, Vector128<double> mask, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 1);
-                case 2:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 2);
-                case 4:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 4);
-                case 8:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherMaskVector128(source, baseAddress, index, mask, 1),
+                2 => GatherMaskVector128(source, baseAddress, index, mask, 2),
+                4 => GatherMaskVector128(source, baseAddress, index, mask, 4),
+                8 => GatherMaskVector128(source, baseAddress, index, mask, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m128i _mm_mask_i64gather_epi32 (__m128i src, int const* base_addr, __m128i vindex, __m128i mask, const int scale)
@@ -1479,19 +1329,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector128<int> GatherMaskVector128(Vector128<int> source, int* baseAddress, Vector128<long> index, Vector128<int> mask, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 1);
-                case 2:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 2);
-                case 4:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 4);
-                case 8:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherMaskVector128(source, baseAddress, index, mask, 1),
+                2 => GatherMaskVector128(source, baseAddress, index, mask, 2),
+                4 => GatherMaskVector128(source, baseAddress, index, mask, 4),
+                8 => GatherMaskVector128(source, baseAddress, index, mask, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m128i _mm_mask_i64gather_epi32 (__m128i src, int const* base_addr, __m128i vindex, __m128i mask, const int scale)
@@ -1500,19 +1345,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector128<uint> GatherMaskVector128(Vector128<uint> source, uint* baseAddress, Vector128<long> index, Vector128<uint> mask, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 1);
-                case 2:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 2);
-                case 4:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 4);
-                case 8:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherMaskVector128(source, baseAddress, index, mask, 1),
+                2 => GatherMaskVector128(source, baseAddress, index, mask, 2),
+                4 => GatherMaskVector128(source, baseAddress, index, mask, 4),
+                8 => GatherMaskVector128(source, baseAddress, index, mask, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m128i _mm_mask_i64gather_epi64 (__m128i src, __int64 const* base_addr, __m128i vindex, __m128i mask, const int scale)
@@ -1521,19 +1361,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector128<long> GatherMaskVector128(Vector128<long> source, long* baseAddress, Vector128<long> index, Vector128<long> mask, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 1);
-                case 2:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 2);
-                case 4:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 4);
-                case 8:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherMaskVector128(source, baseAddress, index, mask, 1),
+                2 => GatherMaskVector128(source, baseAddress, index, mask, 2),
+                4 => GatherMaskVector128(source, baseAddress, index, mask, 4),
+                8 => GatherMaskVector128(source, baseAddress, index, mask, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m128i _mm_mask_i64gather_epi64 (__m128i src, __int64 const* base_addr, __m128i vindex, __m128i mask, const int scale)
@@ -1542,19 +1377,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector128<ulong> GatherMaskVector128(Vector128<ulong> source, ulong* baseAddress, Vector128<long> index, Vector128<ulong> mask, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 1);
-                case 2:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 2);
-                case 4:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 4);
-                case 8:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherMaskVector128(source, baseAddress, index, mask, 1),
+                2 => GatherMaskVector128(source, baseAddress, index, mask, 2),
+                4 => GatherMaskVector128(source, baseAddress, index, mask, 4),
+                8 => GatherMaskVector128(source, baseAddress, index, mask, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m128 _mm_mask_i64gather_ps (__m128 src, float const* base_addr, __m128i vindex, __m128 mask, const int scale)
@@ -1563,19 +1393,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector128<float> GatherMaskVector128(Vector128<float> source, float* baseAddress, Vector128<long> index, Vector128<float> mask, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 1);
-                case 2:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 2);
-                case 4:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 4);
-                case 8:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherMaskVector128(source, baseAddress, index, mask, 1),
+                2 => GatherMaskVector128(source, baseAddress, index, mask, 2),
+                4 => GatherMaskVector128(source, baseAddress, index, mask, 4),
+                8 => GatherMaskVector128(source, baseAddress, index, mask, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m128d _mm_mask_i64gather_pd (__m128d src, double const* base_addr, __m128i vindex, __m128d mask, const int scale)
@@ -1584,19 +1409,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector128<double> GatherMaskVector128(Vector128<double> source, double* baseAddress, Vector128<long> index, Vector128<double> mask, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 1);
-                case 2:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 2);
-                case 4:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 4);
-                case 8:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherMaskVector128(source, baseAddress, index, mask, 1),
+                2 => GatherMaskVector128(source, baseAddress, index, mask, 2),
+                4 => GatherMaskVector128(source, baseAddress, index, mask, 4),
+                8 => GatherMaskVector128(source, baseAddress, index, mask, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m256i _mm256_mask_i32gather_epi32 (__m256i src, int const* base_addr, __m256i vindex, __m256i mask, const int scale)
@@ -1605,19 +1425,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector256<int> GatherMaskVector256(Vector256<int> source, int* baseAddress, Vector256<int> index, Vector256<int> mask, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 1);
-                case 2:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 2);
-                case 4:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 4);
-                case 8:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherMaskVector256(source, baseAddress, index, mask, 1),
+                2 => GatherMaskVector256(source, baseAddress, index, mask, 2),
+                4 => GatherMaskVector256(source, baseAddress, index, mask, 4),
+                8 => GatherMaskVector256(source, baseAddress, index, mask, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m256i _mm256_mask_i32gather_epi32 (__m256i src, int const* base_addr, __m256i vindex, __m256i mask, const int scale)
@@ -1626,19 +1441,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector256<uint> GatherMaskVector256(Vector256<uint> source, uint* baseAddress, Vector256<int> index, Vector256<uint> mask, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 1);
-                case 2:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 2);
-                case 4:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 4);
-                case 8:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherMaskVector256(source, baseAddress, index, mask, 1),
+                2 => GatherMaskVector256(source, baseAddress, index, mask, 2),
+                4 => GatherMaskVector256(source, baseAddress, index, mask, 4),
+                8 => GatherMaskVector256(source, baseAddress, index, mask, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m256i _mm256_mask_i32gather_epi64 (__m256i src, __int64 const* base_addr, __m128i vindex, __m256i mask, const int scale)
@@ -1647,19 +1457,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector256<long> GatherMaskVector256(Vector256<long> source, long* baseAddress, Vector128<int> index, Vector256<long> mask, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 1);
-                case 2:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 2);
-                case 4:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 4);
-                case 8:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherMaskVector256(source, baseAddress, index, mask, 1),
+                2 => GatherMaskVector256(source, baseAddress, index, mask, 2),
+                4 => GatherMaskVector256(source, baseAddress, index, mask, 4),
+                8 => GatherMaskVector256(source, baseAddress, index, mask, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m256i _mm256_mask_i32gather_epi64 (__m256i src, __int64 const* base_addr, __m128i vindex, __m256i mask, const int scale)
@@ -1668,19 +1473,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector256<ulong> GatherMaskVector256(Vector256<ulong> source, ulong* baseAddress, Vector128<int> index, Vector256<ulong> mask, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 1);
-                case 2:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 2);
-                case 4:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 4);
-                case 8:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherMaskVector256(source, baseAddress, index, mask, 1),
+                2 => GatherMaskVector256(source, baseAddress, index, mask, 2),
+                4 => GatherMaskVector256(source, baseAddress, index, mask, 4),
+                8 => GatherMaskVector256(source, baseAddress, index, mask, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m256 _mm256_mask_i32gather_ps (__m256 src, float const* base_addr, __m256i vindex, __m256 mask, const int scale)
@@ -1689,19 +1489,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector256<float> GatherMaskVector256(Vector256<float> source, float* baseAddress, Vector256<int> index, Vector256<float> mask, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 1);
-                case 2:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 2);
-                case 4:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 4);
-                case 8:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherMaskVector256(source, baseAddress, index, mask, 1),
+                2 => GatherMaskVector256(source, baseAddress, index, mask, 2),
+                4 => GatherMaskVector256(source, baseAddress, index, mask, 4),
+                8 => GatherMaskVector256(source, baseAddress, index, mask, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m256d _mm256_mask_i32gather_pd (__m256d src, double const* base_addr, __m128i vindex, __m256d mask, const int scale)
@@ -1710,19 +1505,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector256<double> GatherMaskVector256(Vector256<double> source, double* baseAddress, Vector128<int> index, Vector256<double> mask, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 1);
-                case 2:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 2);
-                case 4:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 4);
-                case 8:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherMaskVector256(source, baseAddress, index, mask, 1),
+                2 => GatherMaskVector256(source, baseAddress, index, mask, 2),
+                4 => GatherMaskVector256(source, baseAddress, index, mask, 4),
+                8 => GatherMaskVector256(source, baseAddress, index, mask, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m128i _mm256_mask_i64gather_epi32 (__m128i src, int const* base_addr, __m256i vindex, __m128i mask, const int scale)
@@ -1731,19 +1521,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector128<int> GatherMaskVector128(Vector128<int> source, int* baseAddress, Vector256<long> index, Vector128<int> mask, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 1);
-                case 2:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 2);
-                case 4:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 4);
-                case 8:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherMaskVector128(source, baseAddress, index, mask, 1),
+                2 => GatherMaskVector128(source, baseAddress, index, mask, 2),
+                4 => GatherMaskVector128(source, baseAddress, index, mask, 4),
+                8 => GatherMaskVector128(source, baseAddress, index, mask, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m128i _mm256_mask_i64gather_epi32 (__m128i src, int const* base_addr, __m256i vindex, __m128i mask, const int scale)
@@ -1752,19 +1537,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector128<uint> GatherMaskVector128(Vector128<uint> source, uint* baseAddress, Vector256<long> index, Vector128<uint> mask, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 1);
-                case 2:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 2);
-                case 4:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 4);
-                case 8:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherMaskVector128(source, baseAddress, index, mask, 1),
+                2 => GatherMaskVector128(source, baseAddress, index, mask, 2),
+                4 => GatherMaskVector128(source, baseAddress, index, mask, 4),
+                8 => GatherMaskVector128(source, baseAddress, index, mask, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m256i _mm256_mask_i64gather_epi64 (__m256i src, __int64 const* base_addr, __m256i vindex, __m256i mask, const int scale)
@@ -1773,19 +1553,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector256<long> GatherMaskVector256(Vector256<long> source, long* baseAddress, Vector256<long> index, Vector256<long> mask, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 1);
-                case 2:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 2);
-                case 4:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 4);
-                case 8:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherMaskVector256(source, baseAddress, index, mask, 1),
+                2 => GatherMaskVector256(source, baseAddress, index, mask, 2),
+                4 => GatherMaskVector256(source, baseAddress, index, mask, 4),
+                8 => GatherMaskVector256(source, baseAddress, index, mask, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m256i _mm256_mask_i64gather_epi64 (__m256i src, __int64 const* base_addr, __m256i vindex, __m256i mask, const int scale)
@@ -1794,19 +1569,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector256<ulong> GatherMaskVector256(Vector256<ulong> source, ulong* baseAddress, Vector256<long> index, Vector256<ulong> mask, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 1);
-                case 2:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 2);
-                case 4:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 4);
-                case 8:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherMaskVector256(source, baseAddress, index, mask, 1),
+                2 => GatherMaskVector256(source, baseAddress, index, mask, 2),
+                4 => GatherMaskVector256(source, baseAddress, index, mask, 4),
+                8 => GatherMaskVector256(source, baseAddress, index, mask, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m128 _mm256_mask_i64gather_ps (__m128 src, float const* base_addr, __m256i vindex, __m128 mask, const int scale)
@@ -1815,19 +1585,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector128<float> GatherMaskVector128(Vector128<float> source, float* baseAddress, Vector256<long> index, Vector128<float> mask, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 1);
-                case 2:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 2);
-                case 4:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 4);
-                case 8:
-                    return GatherMaskVector128(source, baseAddress, index, mask, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherMaskVector128(source, baseAddress, index, mask, 1),
+                2 => GatherMaskVector128(source, baseAddress, index, mask, 2),
+                4 => GatherMaskVector128(source, baseAddress, index, mask, 4),
+                8 => GatherMaskVector128(source, baseAddress, index, mask, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
         /// <summary>
         /// __m256d _mm256_mask_i64gather_pd (__m256d src, double const* base_addr, __m256i vindex, __m256d mask, const int scale)
@@ -1836,19 +1601,14 @@ namespace System.Runtime.Intrinsics.X86
         /// </summary>
         public static unsafe Vector256<double> GatherMaskVector256(Vector256<double> source, double* baseAddress, Vector256<long> index, Vector256<double> mask, byte scale)
         {
-            switch (scale)
+            return scale switch
             {
-                case 1:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 1);
-                case 2:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 2);
-                case 4:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 4);
-                case 8:
-                    return GatherMaskVector256(source, baseAddress, index, mask, 8);
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(scale));
-            }
+                1 => GatherMaskVector256(source, baseAddress, index, mask, 1),
+                2 => GatherMaskVector256(source, baseAddress, index, mask, 2),
+                4 => GatherMaskVector256(source, baseAddress, index, mask, 4),
+                8 => GatherMaskVector256(source, baseAddress, index, mask, 8),
+                _ => throw new ArgumentOutOfRangeException(nameof(scale)),
+            };
         }
 
         /// <summary>
index 8965aef..f9e4f68 100644 (file)
@@ -202,8 +202,7 @@ namespace System.Security
 
             for (int i = 0; i < _children.Count; ++i)
             {
-                ISecurityElementFactory? iseFactory = _children[i] as ISecurityElementFactory;
-                if (iseFactory != null && !(_children[i] is SecurityElement))
+                if (_children[i] is ISecurityElementFactory iseFactory && !(_children[i] is SecurityElement))
                     _children[i] = iseFactory.CreateSecurityElement();
             }
         }
index f55a098..f9bd66f 100644 (file)
@@ -69,23 +69,16 @@ namespace System
         // Convert a StringComparison to a StringComparer
         public static StringComparer FromComparison(StringComparison comparisonType)
         {
-            switch (comparisonType)
+            return comparisonType switch
             {
-                case StringComparison.CurrentCulture:
-                    return CurrentCulture;
-                case StringComparison.CurrentCultureIgnoreCase:
-                    return CurrentCultureIgnoreCase;
-                case StringComparison.InvariantCulture:
-                    return InvariantCulture;
-                case StringComparison.InvariantCultureIgnoreCase:
-                    return InvariantCultureIgnoreCase;
-                case StringComparison.Ordinal:
-                    return Ordinal;
-                case StringComparison.OrdinalIgnoreCase:
-                    return OrdinalIgnoreCase;
-                default:
-                    throw new ArgumentException(SR.NotSupported_StringComparison, nameof(comparisonType));
-            }
+                StringComparison.CurrentCulture => CurrentCulture,
+                StringComparison.CurrentCultureIgnoreCase => CurrentCultureIgnoreCase,
+                StringComparison.InvariantCulture => InvariantCulture,
+                StringComparison.InvariantCultureIgnoreCase => InvariantCultureIgnoreCase,
+                StringComparison.Ordinal => Ordinal,
+                StringComparison.OrdinalIgnoreCase => OrdinalIgnoreCase,
+                _ => throw new ArgumentException(SR.NotSupported_StringComparison, nameof(comparisonType)),
+            };
         }
 
         public static StringComparer Create(CultureInfo culture, bool ignoreCase)
index 2e414cf..aaec296 100644 (file)
@@ -873,8 +873,7 @@ namespace System.Text
 
             public override bool Equals(object? value)
             {
-                DecoderUTF7Fallback? that = value as DecoderUTF7Fallback;
-                if (that != null)
+                if (value is DecoderUTF7Fallback)
                 {
                     return true;
                 }
index 704e2c1..dec0eab 100644 (file)
@@ -773,19 +773,16 @@ namespace System.Threading
                 throw new ArgumentNullException(nameof(tokens));
             }
 
-            switch (tokens.Length)
+            return tokens.Length switch
             {
-                case 0:
-                    throw new ArgumentException(SR.CancellationToken_CreateLinkedToken_TokensIsEmpty);
-                case 1:
-                    return CreateLinkedTokenSource(tokens[0]);
-                case 2:
-                    return CreateLinkedTokenSource(tokens[0], tokens[1]);
-                default:
-                    // a defensive copy is not required as the array has value-items that have only a single reference field,
-                    // hence each item cannot be null itself, and reads of the payloads cannot be torn.
-                    return new LinkedNCancellationTokenSource(tokens);
-            }
+                0 => throw new ArgumentException(SR.CancellationToken_CreateLinkedToken_TokensIsEmpty),
+                1 => CreateLinkedTokenSource(tokens[0]),
+                2 => CreateLinkedTokenSource(tokens[0], tokens[1]),
+
+                // a defensive copy is not required as the array has value-items that have only a single reference field,
+                // hence each item cannot be null itself, and reads of the payloads cannot be torn.
+                _ => new LinkedNCancellationTokenSource(tokens),
+            };
         }
 
         /// <summary>
index 53d35fb..c1a5ac3 100644 (file)
@@ -6659,10 +6659,9 @@ namespace System.Threading.Tasks
                 case TaskStatus.Faulted:
                     var edis = task.GetExceptionDispatchInfos();
                     ExceptionDispatchInfo oceEdi;
-                    OperationCanceledException? oce;
                     if (lookForOce && edis.Count > 0 &&
                         (oceEdi = edis[0]) != null &&
-                        (oce = oceEdi.SourceException as OperationCanceledException) != null)
+                        oceEdi.SourceException is OperationCanceledException oce)
                     {
                         result = TrySetCanceled(oce.CancellationToken, oceEdi);
                     }
@@ -6673,15 +6672,13 @@ namespace System.Threading.Tasks
                     break;
 
                 case TaskStatus.RanToCompletion:
-                    var taskTResult = task as Task<TResult>;
-
                     if (AsyncCausalityTracer.LoggingOn)
                         AsyncCausalityTracer.TraceOperationCompletion(this, AsyncCausalityStatus.Completed);
 
                     if (Task.s_asyncDebuggingEnabled)
                         RemoveFromActiveTasks(this);
 
-                    result = TrySetResult(taskTResult != null ? taskTResult.Result : default);
+                    result = TrySetResult(task is Task<TResult> taskTResult ? taskTResult.Result : default);
                     break;
             }
             return result;
index aaa072f..0343fba 100644 (file)
@@ -67,8 +67,7 @@ namespace System.Threading.Tasks
             Task? task;
 
             // If the IAsyncResult is our task-wrapping IAsyncResult, extract the Task.
-            var twar = asyncResult as TaskWrapperAsyncResult;
-            if (twar != null)
+            if (asyncResult is TaskWrapperAsyncResult twar)
             {
                 task = twar.Task;
                 Debug.Assert(task != null, "TaskWrapperAsyncResult should never wrap a null Task.");
@@ -95,8 +94,7 @@ namespace System.Threading.Tasks
             Task<TResult>? task;
 
             // If the IAsyncResult is our task-wrapping IAsyncResult, extract the Task.
-            var twar = asyncResult as TaskWrapperAsyncResult;
-            if (twar != null)
+            if (asyncResult is TaskWrapperAsyncResult twar)
             {
                 task = twar.Task as Task<TResult>;
                 Debug.Assert(twar.Task != null, "TaskWrapperAsyncResult should never wrap a null Task.");
index 9c77f02..1d3f045 100644 (file)
@@ -296,15 +296,12 @@ namespace System
         {
             get
             {
-                switch (index)
+                return index switch
                 {
-                    case 0:
-                        return Item1;
-                    case 1:
-                        return Item2;
-                    default:
-                        throw new IndexOutOfRangeException();
-                }
+                    0 => Item1,
+                    1 => Item2,
+                    _ => throw new IndexOutOfRangeException(),
+                };
             }
         }
     }
@@ -416,17 +413,13 @@ namespace System
         {
             get
             {
-                switch (index)
+                return index switch
                 {
-                    case 0:
-                        return Item1;
-                    case 1:
-                        return Item2;
-                    case 2:
-                        return Item3;
-                    default:
-                        throw new IndexOutOfRangeException();
-                }
+                    0 => Item1,
+                    1 => Item2,
+                    2 => Item3,
+                    _ => throw new IndexOutOfRangeException(),
+                };
             }
         }
     }
@@ -547,19 +540,14 @@ namespace System
         {
             get
             {
-                switch (index)
+                return index switch
                 {
-                    case 0:
-                        return Item1;
-                    case 1:
-                        return Item2;
-                    case 2:
-                        return Item3;
-                    case 3:
-                        return Item4;
-                    default:
-                        throw new IndexOutOfRangeException();
-                }
+                    0 => Item1,
+                    1 => Item2,
+                    2 => Item3,
+                    3 => Item4,
+                    _ => throw new IndexOutOfRangeException(),
+                };
             }
         }
     }
@@ -689,21 +677,15 @@ namespace System
         {
             get
             {
-                switch (index)
+                return index switch
                 {
-                    case 0:
-                        return Item1;
-                    case 1:
-                        return Item2;
-                    case 2:
-                        return Item3;
-                    case 3:
-                        return Item4;
-                    case 4:
-                        return Item5;
-                    default:
-                        throw new IndexOutOfRangeException();
-                }
+                    0 => Item1,
+                    1 => Item2,
+                    2 => Item3,
+                    3 => Item4,
+                    4 => Item5,
+                    _ => throw new IndexOutOfRangeException(),
+                };
             }
         }
     }
@@ -842,23 +824,16 @@ namespace System
         {
             get
             {
-                switch (index)
+                return index switch
                 {
-                    case 0:
-                        return Item1;
-                    case 1:
-                        return Item2;
-                    case 2:
-                        return Item3;
-                    case 3:
-                        return Item4;
-                    case 4:
-                        return Item5;
-                    case 5:
-                        return Item6;
-                    default:
-                        throw new IndexOutOfRangeException();
-                }
+                    0 => Item1,
+                    1 => Item2,
+                    2 => Item3,
+                    3 => Item4,
+                    4 => Item5,
+                    5 => Item6,
+                    _ => throw new IndexOutOfRangeException(),
+                };
             }
         }
     }
@@ -1006,25 +981,17 @@ namespace System
         {
             get
             {
-                switch (index)
+                return index switch
                 {
-                    case 0:
-                        return Item1;
-                    case 1:
-                        return Item2;
-                    case 2:
-                        return Item3;
-                    case 3:
-                        return Item4;
-                    case 4:
-                        return Item5;
-                    case 5:
-                        return Item6;
-                    case 6:
-                        return Item7;
-                    default:
-                        throw new IndexOutOfRangeException();
-                }
+                    0 => Item1,
+                    1 => Item2,
+                    2 => Item3,
+                    3 => Item4,
+                    4 => Item5,
+                    5 => Item6,
+                    6 => Item7,
+                    _ => throw new IndexOutOfRangeException(),
+                };
             }
         }
     }
@@ -1214,25 +1181,18 @@ namespace System
         {
             get
             {
-                switch (index)
+                return index switch
                 {
-                    case 0:
-                        return Item1;
-                    case 1:
-                        return Item2;
-                    case 2:
-                        return Item3;
-                    case 3:
-                        return Item4;
-                    case 4:
-                        return Item5;
-                    case 5:
-                        return Item6;
-                    case 6:
-                        return Item7;
-                }
-
-                return ((ITupleInternal)Rest)[index - 7];
+                    0 => Item1,
+                    1 => Item2,
+                    2 => Item3,
+                    3 => Item4,
+                    4 => Item5,
+                    5 => Item6,
+                    6 => Item7,
+
+                    _ => ((ITupleInternal)Rest)[index - 7],
+                };
             }
         }
     }
index 6fd28db..216ef5c 100644 (file)
@@ -656,15 +656,12 @@ namespace System
         {
             get
             {
-                switch (index)
+                return index switch
                 {
-                    case 0:
-                        return Item1;
-                    case 1:
-                        return Item2;
-                    default:
-                        throw new IndexOutOfRangeException();
-                }
+                    0 => Item1,
+                    1 => Item2,
+                    _ => throw new IndexOutOfRangeException(),
+                };
             }
         }
     }
@@ -862,17 +859,13 @@ namespace System
         {
             get
             {
-                switch (index)
+                return index switch
                 {
-                    case 0:
-                        return Item1;
-                    case 1:
-                        return Item2;
-                    case 2:
-                        return Item3;
-                    default:
-                        throw new IndexOutOfRangeException();
-                }
+                    0 => Item1,
+                    1 => Item2,
+                    2 => Item3,
+                    _ => throw new IndexOutOfRangeException(),
+                };
             }
         }
     }
@@ -1087,19 +1080,14 @@ namespace System
         {
             get
             {
-                switch (index)
+                return index switch
                 {
-                    case 0:
-                        return Item1;
-                    case 1:
-                        return Item2;
-                    case 2:
-                        return Item3;
-                    case 3:
-                        return Item4;
-                    default:
-                        throw new IndexOutOfRangeException();
-                }
+                    0 => Item1,
+                    1 => Item2,
+                    2 => Item3,
+                    3 => Item4,
+                    _ => throw new IndexOutOfRangeException(),
+                };
             }
         }
     }
@@ -1331,21 +1319,15 @@ namespace System
         {
             get
             {
-                switch (index)
+                return index switch
                 {
-                    case 0:
-                        return Item1;
-                    case 1:
-                        return Item2;
-                    case 2:
-                        return Item3;
-                    case 3:
-                        return Item4;
-                    case 4:
-                        return Item5;
-                    default:
-                        throw new IndexOutOfRangeException();
-                }
+                    0 => Item1,
+                    1 => Item2,
+                    2 => Item3,
+                    3 => Item4,
+                    4 => Item5,
+                    _ => throw new IndexOutOfRangeException(),
+                };
             }
         }
     }
@@ -1594,23 +1576,16 @@ namespace System
         {
             get
             {
-                switch (index)
+                return index switch
                 {
-                    case 0:
-                        return Item1;
-                    case 1:
-                        return Item2;
-                    case 2:
-                        return Item3;
-                    case 3:
-                        return Item4;
-                    case 4:
-                        return Item5;
-                    case 5:
-                        return Item6;
-                    default:
-                        throw new IndexOutOfRangeException();
-                }
+                    0 => Item1,
+                    1 => Item2,
+                    2 => Item3,
+                    3 => Item4,
+                    4 => Item5,
+                    5 => Item6,
+                    _ => throw new IndexOutOfRangeException(),
+                };
             }
         }
     }
@@ -1876,25 +1851,17 @@ namespace System
         {
             get
             {
-                switch (index)
+                return index switch
                 {
-                    case 0:
-                        return Item1;
-                    case 1:
-                        return Item2;
-                    case 2:
-                        return Item3;
-                    case 3:
-                        return Item4;
-                    case 4:
-                        return Item5;
-                    case 5:
-                        return Item6;
-                    case 6:
-                        return Item7;
-                    default:
-                        throw new IndexOutOfRangeException();
-                }
+                    0 => Item1,
+                    1 => Item2,
+                    2 => Item3,
+                    3 => Item4,
+                    4 => Item5,
+                    5 => Item6,
+                    6 => Item7,
+                    _ => throw new IndexOutOfRangeException(),
+                };
             }
         }
     }
@@ -2122,8 +2089,7 @@ namespace System
         public override int GetHashCode()
         {
             // We want to have a limited hash in this case.  We'll use the last 8 elements of the tuple
-            IValueTupleInternal? rest = Rest as IValueTupleInternal;
-            if (rest == null)
+            if (!(Rest is IValueTupleInternal rest))
             {
                 return ValueTuple.CombineHashCodes(Item1?.GetHashCode() ?? 0,
                                                    Item2?.GetHashCode() ?? 0,
@@ -2198,8 +2164,7 @@ namespace System
         private int GetHashCodeCore(IEqualityComparer comparer)
         {
             // We want to have a limited hash in this case.  We'll use the last 8 elements of the tuple
-            IValueTupleInternal? rest = Rest as IValueTupleInternal;
-            if (rest == null)
+            if (!(Rest is IValueTupleInternal rest))
             {
                 return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item1!), comparer.GetHashCode(Item2!), comparer.GetHashCode(Item3!),
                                                    comparer.GetHashCode(Item4!), comparer.GetHashCode(Item5!), comparer.GetHashCode(Item6!),
@@ -2256,41 +2221,28 @@ namespace System
         /// </remarks>
         public override string ToString()
         {
-            IValueTupleInternal? rest = Rest as IValueTupleInternal;
-            if (rest == null)
-            {
-                return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ", " + Item5?.ToString() + ", " + Item6?.ToString() + ", " + Item7?.ToString() + ", " + Rest.ToString() + ")";
-            }
-            else
+            if (Rest is IValueTupleInternal rest)
             {
                 return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ", " + Item5?.ToString() + ", " + Item6?.ToString() + ", " + Item7?.ToString() + ", " + rest.ToStringEnd();
             }
+
+            return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ", " + Item5?.ToString() + ", " + Item6?.ToString() + ", " + Item7?.ToString() + ", " + Rest.ToString() + ")";
         }
 
         string IValueTupleInternal.ToStringEnd()
         {
-            IValueTupleInternal? rest = Rest as IValueTupleInternal;
-            if (rest == null)
-            {
-                return Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ", " + Item5?.ToString() + ", " + Item6?.ToString() + ", " + Item7?.ToString() + ", " + Rest.ToString() + ")";
-            }
-            else
+            if (Rest is IValueTupleInternal rest)
             {
                 return Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ", " + Item5?.ToString() + ", " + Item6?.ToString() + ", " + Item7?.ToString() + ", " + rest.ToStringEnd();
             }
+
+            return Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ", " + Item5?.ToString() + ", " + Item6?.ToString() + ", " + Item7?.ToString() + ", " + Rest.ToString() + ")";
         }
 
         /// <summary>
         /// The number of positions in this data structure.
         /// </summary>
-        int ITuple.Length
-        {
-            get
-            {
-                IValueTupleInternal? rest = Rest as IValueTupleInternal;
-                return rest == null ? 8 : 7 + rest.Length;
-            }
-        }
+        int ITuple.Length => Rest is IValueTupleInternal rest ? 7 + rest.Length : 8;
 
         /// <summary>
         /// Get the element at position <param name="index"/>.
@@ -2317,16 +2269,18 @@ namespace System
                         return Item7;
                 }
 
-                IValueTupleInternal? rest = Rest as IValueTupleInternal;
-                if (rest == null)
+                if (Rest is IValueTupleInternal rest)
                 {
-                    if (index == 7)
-                    {
-                        return Rest;
-                    }
-                    throw new IndexOutOfRangeException();
+                    return rest[index - 7];
+                }
+
+
+                if (index == 7)
+                {
+                    return Rest;
                 }
-                return rest[index - 7];
+
+                throw new IndexOutOfRangeException();
             }
         }
     }