diff --git a/src/coreclr/System.Private.CoreLib/src/System/Attribute.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Attribute.CoreCLR.cs index 3634e8012c21fd..de1aefbe31c0f5 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Attribute.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Attribute.CoreCLR.cs @@ -391,7 +391,7 @@ private static Type[] GetIndexParameterTypes(PropertyInfo element) return indexParamTypes; } - return Type.EmptyTypes; + return []; } private static void AddAttributesToList(List attributeList, Attribute[] attributes, Dictionary types) diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeTypeBuilder.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeTypeBuilder.cs index 6f1bb367159e25..f5afc0b0743d2a 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeTypeBuilder.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeTypeBuilder.cs @@ -1259,13 +1259,13 @@ private RuntimeConstructorBuilder DefineDefaultConstructorNoLock(MethodAttribute if (inst is TypeBuilderInstantiation) con = GetConstructor(inst, genericTypeDefinition.GetConstructor( - BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, EmptyTypes, null)!); + BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, [], null)!); else con = inst.GetConstructor( - BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, EmptyTypes, null); + BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, [], null); } - con ??= m_typeParent!.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, EmptyTypes, null); + con ??= m_typeParent!.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, [], null); if (con == null) throw new NotSupportedException(SR.NotSupported_NoParentDefaultConstructor); diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/MdFieldInfo.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/MdFieldInfo.cs index cda066bba16e20..0455735183b4c6 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/MdFieldInfo.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/MdFieldInfo.cs @@ -122,15 +122,9 @@ public override Type FieldType } } - public override Type[] GetRequiredCustomModifiers() - { - return Type.EmptyTypes; - } + public override Type[] GetRequiredCustomModifiers() => []; - public override Type[] GetOptionalCustomModifiers() - { - return Type.EmptyTypes; - } + public override Type[] GetOptionalCustomModifiers() => []; #endregion } diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/ModifiedType.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/ModifiedType.CoreCLR.cs index 394b6b4ecffa9e..4c3b8cd32ae25d 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/ModifiedType.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/ModifiedType.CoreCLR.cs @@ -30,6 +30,6 @@ internal static Type Create(Type unmodifiedType, Signature? signature, int param private Type[] GetCustomModifiers(bool required) => (_typeSignature._signature != null) ? - _typeSignature._signature.GetCustomModifiersAtOffset(_typeSignature._offset, required) : EmptyTypes; + _typeSignature._signature.GetCustomModifiersAtOffset(_typeSignature._offset, required) : []; } } diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeCustomAttributeData.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeCustomAttributeData.cs index de2f6cf1d2d197..b0101c75e3df1a 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeCustomAttributeData.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeCustomAttributeData.cs @@ -1575,7 +1575,7 @@ private static void AddCustomAttributes( RuntimePropertyInfo? property = (RuntimePropertyInfo?)(type is null ? attributeType.GetProperty(name) : - attributeType.GetProperty(name, type, Type.EmptyTypes)) ?? + attributeType.GetProperty(name, type, [])) ?? throw new CustomAttributeFormatException(SR.Format(SR.RFLCT_InvalidPropFail, name)); RuntimeMethodInfo setMethod = property.GetSetMethod(true)!; diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.CoreCLR.cs index 3a72a2e1174e4b..16ff331c2fdd7c 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.CoreCLR.cs @@ -447,7 +447,7 @@ internal RuntimeType[] GetGenericArgumentsInternal() => RuntimeMethodHandle.GetMethodInstantiationInternal(this); public override Type[] GetGenericArguments() => - RuntimeMethodHandle.GetMethodInstantiationPublic(this) ?? Type.EmptyTypes; + RuntimeMethodHandle.GetMethodInstantiationPublic(this) ?? []; public override MethodInfo GetGenericMethodDefinition() { diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs index 61a4163529e0d1..b2c735bcac7328 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs @@ -287,7 +287,7 @@ public override bool HasDefaultValue if (IsOptional) { // If the argument is marked as optional then the default value is Missing.Value. - defaultValue = Type.Missing; + defaultValue = Missing.Value; } #endregion } @@ -434,16 +434,12 @@ private static DateTime GetRawDateTimeConstant(CustomAttributeData attr) public override Type[] GetRequiredCustomModifiers() { - return m_signature is null ? - Type.EmptyTypes : - m_signature.GetCustomModifiers(PositionImpl + 1, true); + return m_signature is null ? [] : m_signature.GetCustomModifiers(PositionImpl + 1, true); } public override Type[] GetOptionalCustomModifiers() { - return m_signature is null ? - Type.EmptyTypes : - m_signature.GetCustomModifiers(PositionImpl + 1, false); + return m_signature is null ? [] : m_signature.GetCustomModifiers(PositionImpl + 1, false); } public override Type GetModifiedParameterType() => diff --git a/src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs b/src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs index 2bc71d3dfbd59f..e59be872265d3b 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs @@ -578,14 +578,14 @@ internal static Type[] GetInterfaces(RuntimeType type) [LibraryImport(RuntimeHelpers.QCall, EntryPoint = "RuntimeTypeHandle_GetConstraints")] private static partial void GetConstraints(QCallTypeHandle handle, ObjectHandleOnStack types); - internal Type[] GetConstraints() + internal Type[]? GetConstraints() { Type[]? types = null; RuntimeTypeHandle nativeHandle = GetNativeHandle(); GetConstraints(new QCallTypeHandle(ref nativeHandle), ObjectHandleOnStack.Create(ref types)); - return types!; + return types; } [LibraryImport(RuntimeHelpers.QCall, EntryPoint = "QCall_GetGCHandleForTypeHandle")] @@ -744,12 +744,12 @@ internal RuntimeType[] GetInstantiationInternal() return types!; } - internal Type[] GetInstantiationPublic() + internal Type[]? GetInstantiationPublic() { Type[]? types = null; RuntimeTypeHandle nativeHandle = GetNativeHandle(); GetInstantiation(new QCallTypeHandle(ref nativeHandle), ObjectHandleOnStack.Create(ref types), Interop.BOOL.FALSE); - return types!; + return types; } [LibraryImport(RuntimeHelpers.QCall, EntryPoint = "RuntimeTypeHandle_Instantiate")] @@ -1229,12 +1229,12 @@ internal static RuntimeType[] GetMethodInstantiationInternal(RuntimeMethodHandle return types!; } - internal static Type[] GetMethodInstantiationPublic(IRuntimeMethodInfo method) + internal static Type[]? GetMethodInstantiationPublic(IRuntimeMethodInfo method) { - RuntimeType[]? types = null; + Type[]? types = null; GetMethodInstantiation(EnsureNonNullMethodInfo(method).Value, ObjectHandleOnStack.Create(ref types), Interop.BOOL.FALSE); GC.KeepAlive(method); - return types!; + return types; } [MethodImpl(MethodImplOptions.InternalCall)] diff --git a/src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs index cc4ae643e1beb3..c4de3a72051b92 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs @@ -3542,8 +3542,7 @@ internal RuntimeType[] GetGenericArgumentsInternal() public override Type[] GetGenericArguments() { - Type[] types = GetRootElementType().TypeHandle.GetInstantiationPublic(); - return types ?? EmptyTypes; + return GetRootElementType().TypeHandle.GetInstantiationPublic() ?? []; } [RequiresUnreferencedCode("If some of the generic arguments are annotated (either with DynamicallyAccessedMembersAttribute, or generic constraints), trimming can't validate that the requirements of those annotations are met.")] @@ -3636,8 +3635,7 @@ public override Type[] GetGenericParameterConstraints() if (!IsGenericParameter) throw new InvalidOperationException(SR.Arg_NotGenericParameter); - Type[] constraints = new RuntimeTypeHandle(this).GetConstraints(); - return constraints ?? EmptyTypes; + return new RuntimeTypeHandle(this).GetConstraints() ?? []; } #endregion @@ -3756,7 +3754,7 @@ public override Type[] GetFunctionPointerCallingConventions() } // Requires a modified type to return the modifiers. - return EmptyTypes; + return []; } public override Type[] GetFunctionPointerParameterTypes() @@ -3771,7 +3769,7 @@ public override Type[] GetFunctionPointerParameterTypes() if (parameters.Length == 1) { - return EmptyTypes; + return []; } return parameters.AsSpan(1).ToArray(); @@ -3844,7 +3842,7 @@ private void CreateInstanceCheckThis() int consCount = 0; // We cannot use Type.GetTypeArray here because some of the args might be null - Type[] argsType = args.Length != 0 ? new Type[args.Length] : EmptyTypes; + Type[] argsType = args.Length != 0 ? new Type[args.Length] : []; for (int i = 0; i < args.Length; i++) { if (args[i] is object arg) diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeFunctionPointerTypeInfo.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeFunctionPointerTypeInfo.cs index 4eadd228c7c5b4..d29e408197303a 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeFunctionPointerTypeInfo.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeFunctionPointerTypeInfo.cs @@ -35,7 +35,7 @@ public UnificationKey Key public override Assembly Assembly => typeof(object).Assembly; public override IEnumerable CustomAttributes => Array.Empty(); - public override Type[] GetFunctionPointerCallingConventions() => Type.EmptyTypes; + public override Type[] GetFunctionPointerCallingConventions() => []; public override bool ContainsGenericParameters { @@ -66,7 +66,7 @@ public override bool HasSameMetadataDefinitionAs(MemberInfo other) public override Type[] GetFunctionPointerParameterTypes() { if (_key.ParameterTypes.Length == 0) - return Type.EmptyTypes; + return []; Type[] result = new Type[_key.ParameterTypes.Length]; Array.Copy(_key.ParameterTypes, result, result.Length); diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeType.NativeAot.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeType.NativeAot.cs index c417aaad804bb0..0163a849c521cd 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeType.NativeAot.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeType.NativeAot.cs @@ -349,7 +349,7 @@ public override Type[] GetInterfaces() { int count = pEEType->NumInterfaces; if (count == 0) - return EmptyTypes; + return []; Type[] result = new Type[count]; for (int i = 0; i < result.Length; i++) @@ -426,7 +426,7 @@ public override Type[] GenericTypeArguments if (pEEType != null) { if (!pEEType->IsGeneric) - return EmptyTypes; + return []; MethodTableList genericArguments = pEEType->GenericArguments; @@ -448,7 +448,7 @@ public override Type[] GetGenericArguments() return GenericTypeArguments; if (IsGenericTypeDefinition) return GenericTypeParameters; - return EmptyTypes; + return []; } public override bool IsGenericParameter @@ -565,7 +565,7 @@ public override Type[] GetFunctionPointerParameterTypes() uint count = pEEType->NumFunctionPointerParameters; if (count == 0) - return EmptyTypes; + return []; MethodTableList parameterTypes = pEEType->FunctionPointerParameters; @@ -690,7 +690,7 @@ public override Type[] GetFunctionPointerCallingConventions() throw new InvalidOperationException(SR.InvalidOperation_NotFunctionPointer); // Requires a modified type to return the modifiers. - return EmptyTypes; + return []; } [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Type.NativeAot.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Type.NativeAot.cs index 555572840055ec..3a1d2cabd1ba2e 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Type.NativeAot.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Type.NativeAot.cs @@ -29,16 +29,17 @@ internal static unsafe RuntimeType GetTypeFromMethodTable(MethodTable* pMT) return type ?? GetTypeFromMethodTableSlow(pMT); } - private static class AllocationLockHolder + private static class AllocationLock { - public static readonly Lock AllocationLock = new Lock(useTrivialWaits: true); + public static Lock Instance => + field ?? Interlocked.CompareExchange(ref field, new Lock(useTrivialWaits: true), null) ?? field; } [MethodImpl(MethodImplOptions.NoInlining)] private static unsafe RuntimeType GetTypeFromMethodTableSlow(MethodTable* pMT) { // Allocate and set the RuntimeType under a lock - there's no way to free it if there is a race. - using (AllocationLockHolder.AllocationLock.EnterScope()) + lock (AllocationLock.Instance) { ref RuntimeType? runtimeTypeCache = ref Unsafe.AsRef(pMT->WritableData); if (runtimeTypeCache != null) diff --git a/src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ActivatorUtilities.cs b/src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ActivatorUtilities.cs index 652da2fbba0dc3..a1c142c2f39358 100644 --- a/src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ActivatorUtilities.cs +++ b/src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ActivatorUtilities.cs @@ -169,7 +169,7 @@ public static object CreateInstance( Type?[] argumentTypes; if (parameters.Length == 0) { - argumentTypes = Type.EmptyTypes; + argumentTypes = []; } else { diff --git a/src/libraries/System.Private.CoreLib/src/System/DefaultBinder.cs b/src/libraries/System.Private.CoreLib/src/System/DefaultBinder.cs index 7522666bdf328f..f2017450de3a30 100644 --- a/src/libraries/System.Private.CoreLib/src/System/DefaultBinder.cs +++ b/src/libraries/System.Private.CoreLib/src/System/DefaultBinder.cs @@ -11,8 +11,10 @@ namespace System { - internal partial class DefaultBinder : Binder + internal class DefaultBinder : Binder { + internal static readonly DefaultBinder Instance = new DefaultBinder(); + // This method is passed a set of methods and must choose the best // fit. The methods all have the same number of arguments and the object // array args. On exit, this method will choice the best fit method @@ -204,7 +206,7 @@ public sealed override MethodBase BindToMethod( continue; // a default value is available - if (defaultValueBinding && args[index] == Type.Missing) + if (defaultValueBinding && args[index] == Missing.Value) continue; // the argument was null, so it matches with everything @@ -876,7 +878,7 @@ private static int FindMostSpecific(ReadOnlySpan p1, int[] paramO for (int i = 0; i < types.Length; i++) { - if (args != null && args[i] == Type.Missing) + if (args != null && args[i] == Missing.Value) continue; Type c1, c2; diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs index dca87b323f29b8..44eb2ecaaaa557 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Text; +using System.Threading; namespace System.Globalization { @@ -443,12 +444,13 @@ internal sealed partial class CultureData if (tempHashTable == null) { // No table yet, make a new one - tempHashTable = new Dictionary(); + var newTable = new Dictionary(); + tempHashTable = Interlocked.CompareExchange(ref s_cachedRegions, newTable, null) ?? newTable; } else { // Check the hash table - lock (s_lock) + lock (tempHashTable) { tempHashTable.TryGetValue(hashName, out retVal); } @@ -481,14 +483,10 @@ internal sealed partial class CultureData if (retVal != null && !retVal.IsNeutralCulture) { // first add it to the cache - lock (s_lock) + lock (tempHashTable) { tempHashTable[hashName] = retVal; } - - // Copy the hashtable to the corresponding member variables. This will potentially overwrite - // new tables simultaneously created by a new thread, but maximizes thread safety. - s_cachedRegions = tempHashTable; } else { @@ -658,7 +656,6 @@ private static CultureData CreateCultureWithInvariantData() // Cache of cultures we've already looked up private static volatile Dictionary? s_cachedCultures; - private static readonly object s_lock = new object(); internal static CultureData? GetCultureData(string? cultureName, bool useUserOverride) { @@ -683,14 +680,15 @@ private static CultureData CreateCultureWithInvariantData() if (tempHashTable == null) { // No table yet, make a new one - tempHashTable = new Dictionary(); + var newTable = new Dictionary(); + tempHashTable = Interlocked.CompareExchange(ref s_cachedCultures, newTable, null) ?? newTable; } else { // Check the hash table bool ret; CultureData? retVal; - lock (s_lock) + lock (tempHashTable) { ret = tempHashTable.TryGetValue(hashName, out retVal); } @@ -707,15 +705,11 @@ private static CultureData CreateCultureWithInvariantData() } // Found one, add it to the cache - lock (s_lock) + lock (tempHashTable) { tempHashTable[hashName] = culture; } - // Copy the hashtable to the corresponding member variables. This will potentially overwrite - // new tables simultaneously created by a new thread, but maximizes thread safety. - s_cachedCultures = tempHashTable; - return culture; } diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBase.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBase.cs index d638a995b50f52..0bcc9db8b54fb6 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBase.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBase.cs @@ -128,7 +128,7 @@ internal virtual Type[] GetParameterTypes() ReadOnlySpan paramInfo = GetParametersAsSpan(); if (paramInfo.Length == 0) { - return Type.EmptyTypes; + return []; } Type[] parameterTypes = new Type[paramInfo.Length]; diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBaseInvoker.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBaseInvoker.cs index 1a75a10a7898cb..dd46f83e78dc87 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBaseInvoker.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBaseInvoker.cs @@ -357,7 +357,7 @@ BindingFlags invokeAttr RuntimeType sigType = _argTypes[i]; // Convert a Type.Missing to the default value. - if (ReferenceEquals(arg, Type.Missing)) + if (ReferenceEquals(arg, Missing.Value)) { arg = HandleTypeMissing(_method.GetParametersAsSpan()[i], sigType); shouldCopyBack[i] = true; diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/ModifiedFunctionPointerType.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/ModifiedFunctionPointerType.cs index 0de9f152c6b5a1..235877c85a5bd9 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/ModifiedFunctionPointerType.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/ModifiedFunctionPointerType.cs @@ -79,7 +79,7 @@ public override Type[] GetFunctionPointerCallingConventions() break; } - return builder.Count == 0 ? EmptyTypes : builder.ToArray(); + return builder.ToArray(); } } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/ParameterInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/ParameterInfo.cs index 5285f69b919767..1b8355c30f0800 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/ParameterInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/ParameterInfo.cs @@ -50,8 +50,8 @@ public virtual object[] GetCustomAttributes(Type attributeType, bool inherit) public virtual Type GetModifiedParameterType() => throw new NotSupportedException(); - public virtual Type[] GetOptionalCustomModifiers() => Type.EmptyTypes; - public virtual Type[] GetRequiredCustomModifiers() => Type.EmptyTypes; + public virtual Type[] GetOptionalCustomModifiers() => []; + public virtual Type[] GetRequiredCustomModifiers() => []; public virtual int MetadataToken => MetadataToken_ParamDef; diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/PropertyInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/PropertyInfo.cs index fa9c8c2cecec9d..aceba322a915ea 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/PropertyInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/PropertyInfo.cs @@ -34,8 +34,8 @@ protected PropertyInfo() { } public abstract MethodInfo? GetSetMethod(bool nonPublic); public virtual Type GetModifiedPropertyType() => throw new NotSupportedException(); - public virtual Type[] GetOptionalCustomModifiers() => Type.EmptyTypes; - public virtual Type[] GetRequiredCustomModifiers() => Type.EmptyTypes; + public virtual Type[] GetOptionalCustomModifiers() => []; + public virtual Type[] GetRequiredCustomModifiers() => []; [DebuggerHidden] [DebuggerStepThrough] diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/ReflectionTypeLoadException.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/ReflectionTypeLoadException.cs index 975b3993017e50..f885e45744a7f0 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/ReflectionTypeLoadException.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/ReflectionTypeLoadException.cs @@ -20,7 +20,7 @@ public ReflectionTypeLoadException(Type?[]? classes, Exception?[]? exceptions) : public ReflectionTypeLoadException(Type?[]? classes, Exception?[]? exceptions, string? message) : base(message) { - Types = classes ?? Type.EmptyTypes; + Types = classes ?? []; LoaderExceptions = exceptions ?? Array.Empty(); HResult = HResults.COR_E_REFLECTIONTYPELOAD; } @@ -29,7 +29,7 @@ public ReflectionTypeLoadException(Type?[]? classes, Exception?[]? exceptions, s private ReflectionTypeLoadException(SerializationInfo info, StreamingContext context) : base(info, context) { - Types = Type.EmptyTypes; + Types = []; LoaderExceptions = (Exception?[]?)info.GetValue("Exceptions", typeof(Exception[])) ?? Array.Empty(); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/SignatureGenericParameterType.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/SignatureGenericParameterType.cs index 7bd1df5bca35f9..fc0df566e5ccc8 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/SignatureGenericParameterType.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/SignatureGenericParameterType.cs @@ -32,8 +32,8 @@ protected SignatureGenericParameterType(int position) internal sealed override SignatureType? ElementType => null; public sealed override int GetArrayRank() => throw new ArgumentException(SR.Argument_HasToBeArrayClass); public sealed override Type GetGenericTypeDefinition() => throw new InvalidOperationException(SR.InvalidOperation_NotGenericType); - public sealed override Type[] GetGenericArguments() => EmptyTypes; - public sealed override Type[] GenericTypeArguments => EmptyTypes; + public sealed override Type[] GetGenericArguments() => []; + public sealed override Type[] GenericTypeArguments => []; public sealed override int GenericParameterPosition => _position; public abstract override string Name { get; } public sealed override string? Namespace => null; diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/SignatureHasElementType.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/SignatureHasElementType.cs index 664a3301f1a902..31d252b2560441 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/SignatureHasElementType.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/SignatureHasElementType.cs @@ -33,8 +33,8 @@ protected SignatureHasElementType(SignatureType elementType) internal sealed override SignatureType? ElementType => _elementType; public abstract override int GetArrayRank(); public sealed override Type GetGenericTypeDefinition() => throw new InvalidOperationException(SR.InvalidOperation_NotGenericType); - public sealed override Type[] GetGenericArguments() => EmptyTypes; - public sealed override Type[] GenericTypeArguments => EmptyTypes; + public sealed override Type[] GetGenericArguments() => []; + public sealed override Type[] GenericTypeArguments => []; public sealed override int GenericParameterPosition => throw new InvalidOperationException(SR.Arg_NotGenericParameter); public sealed override string Name => _elementType.Name + Suffix; public sealed override string? Namespace => _elementType.Namespace; diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/TypeInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/TypeInfo.cs index aa1a699bdeac08..c642cbca62df57 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/TypeInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/TypeInfo.cs @@ -13,7 +13,7 @@ protected TypeInfo() { } TypeInfo IReflectableType.GetTypeInfo() => this; public virtual Type AsType() => this; - public virtual Type[] GenericTypeParameters => IsGenericTypeDefinition ? GetGenericArguments() : EmptyTypes; + public virtual Type[] GenericTypeParameters => IsGenericTypeDefinition ? GetGenericArguments() : []; [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicEvents | DynamicallyAccessedMemberTypes.NonPublicEvents)] public virtual EventInfo? GetDeclaredEvent(string name) => GetEvent(name, DeclaredOnlyLookup); diff --git a/src/libraries/System.Private.CoreLib/src/System/StartupHookProvider.cs b/src/libraries/System.Private.CoreLib/src/System/StartupHookProvider.cs index eaf92e10beb5c4..17f4ef76420150 100644 --- a/src/libraries/System.Private.CoreLib/src/System/StartupHookProvider.cs +++ b/src/libraries/System.Private.CoreLib/src/System/StartupHookProvider.cs @@ -172,7 +172,7 @@ private static void CallStartupHook(StartupHookNameOrPath startupHook) MethodInfo? initializeMethod = type.GetMethod(InitializeMethodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static, null, // use default binder - Type.EmptyTypes, // parameters + [], // parameters null); // no parameter modifiers if (initializeMethod == null) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Type.cs b/src/libraries/System.Private.CoreLib/src/System/Type.cs index 6020b6848a7d5f..61ce2deace997a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Type.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Type.cs @@ -76,11 +76,11 @@ public bool IsInterface [Intrinsic] public virtual Type GetGenericTypeDefinition() => throw new NotSupportedException(SR.NotSupported_SubclassOverride); - public virtual Type[] GenericTypeArguments => (IsGenericType && !IsGenericTypeDefinition) ? GetGenericArguments() : EmptyTypes; + public virtual Type[] GenericTypeArguments => (IsGenericType && !IsGenericTypeDefinition) ? GetGenericArguments() : []; public virtual Type[] GetGenericArguments() => throw new NotSupportedException(SR.NotSupported_SubclassOverride); - public virtual Type[] GetOptionalCustomModifiers() => EmptyTypes; - public virtual Type[] GetRequiredCustomModifiers() => EmptyTypes; + public virtual Type[] GetOptionalCustomModifiers() => []; + public virtual Type[] GetRequiredCustomModifiers() => []; public virtual int GenericParameterPosition => throw new InvalidOperationException(SR.Arg_NotGenericParameter); public virtual GenericParameterAttributes GenericParameterAttributes => throw new NotSupportedException(); @@ -153,7 +153,7 @@ public bool IsValueType public ConstructorInfo? TypeInitializer { [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] - get => GetConstructorImpl(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, CallingConventions.Any, EmptyTypes, null); + get => GetConstructorImpl(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, CallingConventions.Any, [], null); } [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] @@ -723,13 +723,10 @@ public override int GetHashCode() [Obsolete(Obsoletions.ReflectionOnlyLoadingMessage, DiagnosticId = Obsoletions.ReflectionOnlyLoadingDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] public static Type? ReflectionOnlyGetType(string typeName, bool throwIfNotFound, bool ignoreCase) => throw new PlatformNotSupportedException(SR.PlatformNotSupported_ReflectionOnly); - public static Binder DefaultBinder => - field ?? - Interlocked.CompareExchange(ref field, new DefaultBinder(), null) ?? - field; + public static Binder DefaultBinder => System.DefaultBinder.Instance; public static readonly char Delimiter = '.'; - public static readonly Type[] EmptyTypes = Array.Empty(); + public static readonly Type[] EmptyTypes = []; public static readonly object Missing = Reflection.Missing.Value; public static readonly MemberFilter FilterAttribute = FilterAttributeImpl!;