Skip to content

Commit 2aaae1f

Browse files
committed
Use collection expressions instead of Types.Empty in CoreLib
1 parent afcc083 commit 2aaae1f

21 files changed

+40
-52
lines changed

src/coreclr/System.Private.CoreLib/src/System/Attribute.CoreCLR.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ private static Type[] GetIndexParameterTypes(PropertyInfo element)
391391
return indexParamTypes;
392392
}
393393

394-
return Type.EmptyTypes;
394+
return [];
395395
}
396396

397397
private static void AddAttributesToList(List<Attribute> attributeList, Attribute[] attributes, Dictionary<Type, AttributeUsageAttribute> types)

src/coreclr/System.Private.CoreLib/src/System/Reflection/MdFieldInfo.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,9 @@ public override Type FieldType
122122
}
123123
}
124124

125-
public override Type[] GetRequiredCustomModifiers()
126-
{
127-
return Type.EmptyTypes;
128-
}
125+
public override Type[] GetRequiredCustomModifiers() => [];
129126

130-
public override Type[] GetOptionalCustomModifiers()
131-
{
132-
return Type.EmptyTypes;
133-
}
127+
public override Type[] GetOptionalCustomModifiers() => [];
134128

135129
#endregion
136130
}

src/coreclr/System.Private.CoreLib/src/System/Reflection/ModifiedType.CoreCLR.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ internal static Type Create(Type unmodifiedType, Signature? signature, int param
3030

3131
private Type[] GetCustomModifiers(bool required) =>
3232
(_typeSignature._signature != null) ?
33-
_typeSignature._signature.GetCustomModifiersAtOffset(_typeSignature._offset, required) : EmptyTypes;
33+
_typeSignature._signature.GetCustomModifiersAtOffset(_typeSignature._offset, required) : [];
3434
}
3535
}

src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeCustomAttributeData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1575,7 +1575,7 @@ private static void AddCustomAttributes(
15751575

15761576
RuntimePropertyInfo? property = (RuntimePropertyInfo?)(type is null ?
15771577
attributeType.GetProperty(name) :
1578-
attributeType.GetProperty(name, type, Type.EmptyTypes)) ??
1578+
attributeType.GetProperty(name, type, [])) ??
15791579
throw new CustomAttributeFormatException(SR.Format(SR.RFLCT_InvalidPropFail, name));
15801580
RuntimeMethodInfo setMethod = property.GetSetMethod(true)!;
15811581

src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.CoreCLR.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ internal RuntimeType[] GetGenericArgumentsInternal() =>
447447
RuntimeMethodHandle.GetMethodInstantiationInternal(this);
448448

449449
public override Type[] GetGenericArguments() =>
450-
RuntimeMethodHandle.GetMethodInstantiationPublic(this) ?? Type.EmptyTypes;
450+
RuntimeMethodHandle.GetMethodInstantiationPublic(this) ?? [];
451451

452452
public override MethodInfo GetGenericMethodDefinition()
453453
{

src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -434,16 +434,12 @@ private static DateTime GetRawDateTimeConstant(CustomAttributeData attr)
434434

435435
public override Type[] GetRequiredCustomModifiers()
436436
{
437-
return m_signature is null ?
438-
Type.EmptyTypes :
439-
m_signature.GetCustomModifiers(PositionImpl + 1, true);
437+
return m_signature is null ? [] : m_signature.GetCustomModifiers(PositionImpl + 1, true);
440438
}
441439

442440
public override Type[] GetOptionalCustomModifiers()
443441
{
444-
return m_signature is null ?
445-
Type.EmptyTypes :
446-
m_signature.GetCustomModifiers(PositionImpl + 1, false);
442+
return m_signature is null ? [] : m_signature.GetCustomModifiers(PositionImpl + 1, false);
447443
}
448444

449445
public override Type GetModifiedParameterType() =>

src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ internal static object CreateInstanceForAnotherGenericParameter(
227227
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] RuntimeType type,
228228
RuntimeType genericParameter)
229229
{
230-
Debug.Assert(type.GetConstructor(Type.EmptyTypes) is ConstructorInfo c && c.IsPublic,
230+
Debug.Assert(type.GetConstructor([]) is ConstructorInfo c && c.IsPublic,
231231
$"CreateInstanceForAnotherGenericParameter requires {nameof(type)} to have a public parameterless constructor so it can be annotated for trimming without preserving private constructors.");
232232

233233
object? instantiatedObject = null;
@@ -251,7 +251,7 @@ internal static object CreateInstanceForAnotherGenericParameter(
251251
RuntimeType genericParameter1,
252252
RuntimeType genericParameter2)
253253
{
254-
Debug.Assert(type.GetConstructor(Type.EmptyTypes) is ConstructorInfo c && c.IsPublic,
254+
Debug.Assert(type.GetConstructor([]) is ConstructorInfo c && c.IsPublic,
255255
$"CreateInstanceForAnotherGenericParameter requires {nameof(type)} to have a public parameterless constructor so it can be annotated for trimming without preserving private constructors.");
256256

257257
object? instantiatedObject = null;

src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3542,8 +3542,7 @@ internal RuntimeType[] GetGenericArgumentsInternal()
35423542

35433543
public override Type[] GetGenericArguments()
35443544
{
3545-
Type[] types = GetRootElementType().TypeHandle.GetInstantiationPublic();
3546-
return types ?? EmptyTypes;
3545+
return GetRootElementType().TypeHandle.GetInstantiationPublic() ?? [];
35473546
}
35483547

35493548
[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()
36363635
if (!IsGenericParameter)
36373636
throw new InvalidOperationException(SR.Arg_NotGenericParameter);
36383637

3639-
Type[] constraints = new RuntimeTypeHandle(this).GetConstraints();
3640-
return constraints ?? EmptyTypes;
3638+
return new RuntimeTypeHandle(this).GetConstraints() ?? [];
36413639
}
36423640
#endregion
36433641

@@ -3756,7 +3754,7 @@ public override Type[] GetFunctionPointerCallingConventions()
37563754
}
37573755

37583756
// Requires a modified type to return the modifiers.
3759-
return EmptyTypes;
3757+
return [];
37603758
}
37613759

37623760
public override Type[] GetFunctionPointerParameterTypes()

src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeFunctionPointerTypeInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public UnificationKey Key
3535

3636
public override Assembly Assembly => typeof(object).Assembly;
3737
public override IEnumerable<CustomAttributeData> CustomAttributes => Array.Empty<CustomAttributeData>();
38-
public override Type[] GetFunctionPointerCallingConventions() => Type.EmptyTypes;
38+
public override Type[] GetFunctionPointerCallingConventions() => [];
3939

4040
public override bool ContainsGenericParameters
4141
{
@@ -66,7 +66,7 @@ public override bool HasSameMetadataDefinitionAs(MemberInfo other)
6666
public override Type[] GetFunctionPointerParameterTypes()
6767
{
6868
if (_key.ParameterTypes.Length == 0)
69-
return Type.EmptyTypes;
69+
return [];
7070

7171
Type[] result = new Type[_key.ParameterTypes.Length];
7272
Array.Copy(_key.ParameterTypes, result, result.Length);

src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeType.NativeAot.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ public override Type[] GetInterfaces()
349349
{
350350
int count = pEEType->NumInterfaces;
351351
if (count == 0)
352-
return EmptyTypes;
352+
return [];
353353

354354
Type[] result = new Type[count];
355355
for (int i = 0; i < result.Length; i++)
@@ -426,7 +426,7 @@ public override Type[] GenericTypeArguments
426426
if (pEEType != null)
427427
{
428428
if (!pEEType->IsGeneric)
429-
return EmptyTypes;
429+
return [];
430430

431431
MethodTableList genericArguments = pEEType->GenericArguments;
432432

@@ -448,7 +448,7 @@ public override Type[] GetGenericArguments()
448448
return GenericTypeArguments;
449449
if (IsGenericTypeDefinition)
450450
return GenericTypeParameters;
451-
return EmptyTypes;
451+
return [];
452452
}
453453

454454
public override bool IsGenericParameter
@@ -565,7 +565,7 @@ public override Type[] GetFunctionPointerParameterTypes()
565565

566566
uint count = pEEType->NumFunctionPointerParameters;
567567
if (count == 0)
568-
return EmptyTypes;
568+
return [];
569569

570570
MethodTableList parameterTypes = pEEType->FunctionPointerParameters;
571571

@@ -690,7 +690,7 @@ public override Type[] GetFunctionPointerCallingConventions()
690690
throw new InvalidOperationException(SR.InvalidOperation_NotFunctionPointer);
691691

692692
// Requires a modified type to return the modifiers.
693-
return EmptyTypes;
693+
return [];
694694
}
695695

696696
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]

0 commit comments

Comments
 (0)