Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Type.EmptyTypes consistently #45112

Merged
merged 1 commit into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ private static Type[] GetIndexParameterTypes(PropertyInfo element)
return indexParamTypes;
}

return Array.Empty<Type>();
return Type.EmptyTypes;
}

private static void AddAttributesToList(List<Attribute> attributeList, Attribute[] attributes, Dictionary<Type, AttributeUsageAttribute> types)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ internal void ReleaseBakedStructures()
m_exceptions = null;
}

internal override Type[] GetParameterTypes() => m_parameterTypes ??= Array.Empty<Type>();
internal override Type[] GetParameterTypes() => m_parameterTypes ??= Type.EmptyTypes;

internal static Type? GetMethodBaseReturnType(MethodBase? method)
{
Expand Down Expand Up @@ -306,7 +306,7 @@ internal void SetToken(int token)

internal SignatureHelper GetMethodSignature()
{
m_parameterTypes ??= Array.Empty<Type>();
m_parameterTypes ??= Type.EmptyTypes;

m_signature = SignatureHelper.GetMethodSigHelper(m_module, m_callingConvention, m_inst != null ? m_inst.Length : 0,
m_returnType, m_returnTypeRequiredCustomModifiers, m_returnTypeOptionalCustomModifiers,
Expand Down Expand Up @@ -538,7 +538,7 @@ public override bool IsDefined(Type attributeType, bool inherit)

public override bool IsGenericMethod => m_inst != null;

public override Type[] GetGenericArguments() => m_inst ?? Array.Empty<Type>();
public override Type[] GetGenericArguments() => m_inst ?? Type.EmptyTypes;

public override MethodInfo MakeGenericMethod(params Type[] typeArguments)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal SymbolMethod(ModuleBuilder mod, int token, Type arrayClass, string meth
}
else
{
m_parameterTypes = Array.Empty<Type>();
m_parameterTypes = Type.EmptyTypes;
}

m_module = mod;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ public override Type[] GetInterfaces()

if (m_typeInterfaces == null)
{
return Array.Empty<Type>();
return Type.EmptyTypes;
}

return m_typeInterfaces.ToArray();
Expand Down Expand Up @@ -1188,7 +1188,7 @@ public override Type MakeGenericType(params Type[] typeArguments)
return TypeBuilderInstantiation.MakeGenericType(this, typeArguments);
}

public override Type[] GetGenericArguments() => m_inst ?? Array.Empty<Type>();
public override Type[] GetGenericArguments() => m_inst ?? Type.EmptyTypes;

// If a TypeBuilder is generic, it must be a generic type definition
// All instantiated generic types are TypeBuilderInstantiation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ public override Type FieldType

public override Type[] GetRequiredCustomModifiers()
{
return Array.Empty<Type>();
return Type.EmptyTypes;
}

public override Type[] GetOptionalCustomModifiers()
{
return Array.Empty<Type>();
return Type.EmptyTypes;
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ internal RuntimeType[] GetGenericArgumentsInternal() =>
RuntimeMethodHandle.GetMethodInstantiationInternal(this);

public override Type[] GetGenericArguments() =>
RuntimeMethodHandle.GetMethodInstantiationPublic(this) ?? Array.Empty<Type>();
RuntimeMethodHandle.GetMethodInstantiationPublic(this) ?? Type.EmptyTypes;

public override MethodInfo GetGenericMethodDefinition()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3230,7 +3230,7 @@ internal RuntimeType[] GetGenericArgumentsInternal()
public override Type[] GetGenericArguments()
{
Type[] types = GetRootElementType().GetTypeHandleInternal().GetInstantiationPublic();
return types ?? Array.Empty<Type>();
return types ?? Type.EmptyTypes;
}

public override Type MakeGenericType(Type[] instantiation)
Expand Down Expand Up @@ -3315,7 +3315,7 @@ public override Type[] GetGenericParameterConstraints()
throw new InvalidOperationException(SR.Arg_NotGenericParameter);

Type[] constraints = new RuntimeTypeHandle(this).GetConstraints();
return constraints ?? Array.Empty<Type>();
return constraints ?? Type.EmptyTypes;
}
#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static void Prepare(StreamReader jittraceStream, out int successfulPrepar
int signatureLen = int.Parse(methodStrComponents[2]);
string[] methodInstantiationArgComponents = SplitAndUnescape(methodStrComponents[3], innerCsvEscapeChar, innerCsvEscapeCharArray);
int genericMethodArgCount = int.Parse(methodInstantiationArgComponents[0]);
Type[] methodArgs = genericMethodArgCount != 0 ? new Type[genericMethodArgCount] : Array.Empty<Type>();
Type[] methodArgs = genericMethodArgCount != 0 ? new Type[genericMethodArgCount] : Type.EmptyTypes;
bool abortMethodDiscovery = false;
for (int iMethodArg = 0; iMethodArg < genericMethodArgCount; iMethodArg++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void PopulateSymbolTableWithName(Type callingType, ArgumentObject[] argum

string ICSharpBinder.Name => "Invoke";

Type[] ICSharpInvokeOrInvokeMemberBinder.TypeArguments => Array.Empty<Type>();
Type[] ICSharpInvokeOrInvokeMemberBinder.TypeArguments => Type.EmptyTypes;

CSharpCallFlags ICSharpInvokeOrInvokeMemberBinder.Flags => _flags;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void PopulateSymbolTableWithName(Type callingType, ArgumentObject[] argum

public bool StaticCall => true;

public Type[] TypeArguments => Array.Empty<Type>();
public Type[] TypeArguments => Type.EmptyTypes;

public string Name => ".ctor";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ private static bool IsTypeParameterEquivalentToTypeInst(this Type typeParam, Typ
}

// See if MetadataToken property is available.
PropertyInfo property = memberInfo.GetProperty("MetadataToken", typeof(int), Array.Empty<Type>());
PropertyInfo property = memberInfo.GetProperty("MetadataToken", typeof(int), Type.EmptyTypes);

if (property is not null && property.CanRead)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static int Main(string[] args)
{
ServiceProvider provider = new ServiceCollection().BuildServiceProvider();

ObjectFactory factory = ActivatorUtilities.CreateFactory(typeof(ServiceA), Array.Empty<Type>());
ObjectFactory factory = ActivatorUtilities.CreateFactory(typeof(ServiceA), Type.EmptyTypes);
ServiceA serviceA = factory(provider, null) as ServiceA;
ServiceB serviceB = ActivatorUtilities.CreateInstance(provider, typeof(ServiceB)) as ServiceB;
ServiceC serviceC = ActivatorUtilities.CreateInstance<ServiceC>(provider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ protected Attribute GetDefaultAttribute(Type attributeType)
}
else
{
ConstructorInfo ci = reflect.UnderlyingSystemType.GetConstructor(Array.Empty<Type>());
ConstructorInfo ci = reflect.UnderlyingSystemType.GetConstructor(Type.EmptyTypes);
if (ci != null)
{
attr = (Attribute)ci.Invoke(Array.Empty<object>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private bool ItemTypeHasDefaultConstructor
}

const BindingFlags BindingFlags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance;
return itemType.GetConstructor(BindingFlags, null, Array.Empty<Type>(), null) != null;
return itemType.GetConstructor(BindingFlags, null, Type.EmptyTypes, null) != null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ private MethodInfo GetMethodValue
if (_propInfo == null)
{
BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.GetProperty;
_propInfo = _componentClass.GetProperty(Name, bindingFlags, binder: null, PropertyType, Array.Empty<Type>(), Array.Empty<ParameterModifier>());
_propInfo = _componentClass.GetProperty(Name, bindingFlags, binder: null, PropertyType, Type.EmptyTypes, Array.Empty<ParameterModifier>());
}
if (_propInfo != null)
{
Expand Down Expand Up @@ -351,7 +351,7 @@ private MethodInfo ResetMethodValue

if (_receiverType == null)
{
args = Array.Empty<Type>();
args = Type.EmptyTypes;
}
else
{
Expand Down Expand Up @@ -382,7 +382,7 @@ private MethodInfo SetMethodValue
for (Type t = ComponentType.BaseType; t != null && t != typeof(object); t = t.BaseType)
{
BindingFlags bindingFlags = BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance;
PropertyInfo p = t.GetProperty(name, bindingFlags, binder: null, PropertyType, Array.Empty<Type>(), null);
PropertyInfo p = t.GetProperty(name, bindingFlags, binder: null, PropertyType, Type.EmptyTypes, null);
if (p != null)
{
_setMethod = p.GetSetMethod(nonPublic: false);
Expand All @@ -403,7 +403,7 @@ private MethodInfo SetMethodValue
if (_propInfo == null)
{
BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.GetProperty;
_propInfo = _componentClass.GetProperty(Name, bindingFlags, binder: null, PropertyType, Array.Empty<Type>(), Array.Empty<ParameterModifier>());
_propInfo = _componentClass.GetProperty(Name, bindingFlags, binder: null, PropertyType, Type.EmptyTypes, Array.Empty<ParameterModifier>());
}
if (_propInfo != null)
{
Expand Down Expand Up @@ -435,7 +435,7 @@ private MethodInfo ShouldSerializeMethodValue

if (_receiverType == null)
{
args = Array.Empty<Type>();
args = Type.EmptyTypes;
}
else
{
Expand Down Expand Up @@ -767,7 +767,7 @@ protected override void FillAttributes(IList attributes)
}
else
{
memberInfo = currentReflectType.GetProperty(Name, bindingFlags, binder: null, PropertyType, Array.Empty<Type>(), Array.Empty<ParameterModifier>());
memberInfo = currentReflectType.GetProperty(Name, bindingFlags, binder: null, PropertyType, Type.EmptyTypes, Array.Empty<ParameterModifier>());
}

// Get custom attributes for the member info.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public override object CreateInstance(IServiceProvider provider, Type objectType
}
else
{
argTypes = Array.Empty<Type>();
argTypes = Type.EmptyTypes;
}

obj = objectType.GetConstructor(argTypes)?.Invoke(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace System.Composition.Convention
/// </summary>
public class PartConventionBuilder
{
private readonly Type[] _emptyTypeArray = Array.Empty<Type>();
private readonly Type[] _emptyTypeArray = Type.EmptyTypes;
private static List<Attribute> s_onImportsSatisfiedAttributeList;
private static readonly List<Attribute> s_importingConstructorList = new List<Attribute>() { new ImportingConstructorAttribute() };
private static readonly Type s_exportAttributeType = typeof(ExportAttribute);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private void EmitInvocationExpression(Expression expr, CompilationFlags flags)
if (typeof(LambdaExpression).IsAssignableFrom(expr.Type))
{
// if the invoke target is a lambda expression tree, first compile it into a delegate
expr = Expression.Call(expr, expr.Type.GetMethod("Compile", Array.Empty<Type>())!);
expr = Expression.Call(expr, expr.Type.GetMethod("Compile", Type.EmptyTypes)!);
}

EmitMethodCall(expr, expr.Type.GetInvokeMethod(), node, CompilationFlags.EmitAsNoTail | CompilationFlags.EmitExpressionStart);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2671,7 +2671,7 @@ private void CompileInvocationExpression(Expression expr)

if (typeof(LambdaExpression).IsAssignableFrom(node.Expression.Type))
{
MethodInfo compMethod = node.Expression.Type.GetMethod("Compile", Array.Empty<Type>())!;
MethodInfo compMethod = node.Expression.Type.GetMethod("Compile", Type.EmptyTypes)!;
CompileMethodCallExpression(
Expression.Call(
node.Expression,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static IEnumerable<object[]> ExcessiveLengthOpenGenericTypeArgs()

public static IEnumerable<object[]> EmptyTypeArgs()
{
yield return new object[] { Array.Empty<Type>() };
yield return new object[] { Type.EmptyTypes };
}

public static IEnumerable<object[]> ByRefTypeArgs()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public void CatchFromExternallyThrownString(bool useInterpreter)
ModuleBuilder module = assembly.DefineDynamicModule("Name");
TypeBuilder type = module.DefineType("Type");
MethodBuilder throwingMethod = type.DefineMethod(
"WillThrow", MethodAttributes.Public | MethodAttributes.Static, typeof(void), Array.Empty<Type>());
"WillThrow", MethodAttributes.Public | MethodAttributes.Static, typeof(void), Type.EmptyTypes);
ILGenerator ilGen = throwingMethod.GetILGenerator();
ilGen.Emit(OpCodes.Ldstr, "An Exceptional Exception!");
ilGen.Emit(OpCodes.Throw);
Expand Down Expand Up @@ -887,7 +887,7 @@ public void FilterBeforeInnerFinally(bool useInterpreter)
*/

ConstantExpression builder = Expression.Constant(sb);
Type[] noTypes = Array.Empty<Type>();
Type[] noTypes = Type.EmptyTypes;
TryExpression tryExp = Expression.TryCatch(
Expression.TryFinally(
Expression.Block(
Expand All @@ -911,7 +911,7 @@ public void FilterBeforeInnerFault(bool useInterpreter)
{
StringBuilder sb = new StringBuilder();
ConstantExpression builder = Expression.Constant(sb);
Type[] noTypes = Array.Empty<Type>();
Type[] noTypes = Type.EmptyTypes;
TryExpression tryExp = Expression.TryCatch(
Expression.TryFault(
Expression.Block(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public virtual object[] GetCustomAttributes(Type attributeType, bool inherit)
return Array.Empty<object>();
}

public virtual Type[] GetOptionalCustomModifiers() => Array.Empty<Type>();
public virtual Type[] GetRequiredCustomModifiers() => Array.Empty<Type>();
public virtual Type[] GetOptionalCustomModifiers() => Type.EmptyTypes;
public virtual Type[] GetRequiredCustomModifiers() => Type.EmptyTypes;

public virtual int MetadataToken => MetadataToken_ParamDef;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ protected PropertyInfo() { }
public MethodInfo? GetSetMethod() => GetSetMethod(nonPublic: false);
public abstract MethodInfo? GetSetMethod(bool nonPublic);

public virtual Type[] GetOptionalCustomModifiers() => Array.Empty<Type>();
public virtual Type[] GetRequiredCustomModifiers() => Array.Empty<Type>();
public virtual Type[] GetOptionalCustomModifiers() => Type.EmptyTypes;
public virtual Type[] GetRequiredCustomModifiers() => Type.EmptyTypes;

[DebuggerHidden]
[DebuggerStepThrough]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,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() => Array.Empty<Type>();
public sealed override Type[] GenericTypeArguments => Array.Empty<Type>();
public sealed override Type[] GetGenericArguments() => Type.EmptyTypes;
public sealed override Type[] GenericTypeArguments => Type.EmptyTypes;
public sealed override int GenericParameterPosition => _position;
public abstract override string Name { get; }
public sealed override string? Namespace => null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,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() => Array.Empty<Type>();
public sealed override Type[] GenericTypeArguments => Array.Empty<Type>();
public sealed override Type[] GetGenericArguments() => Type.EmptyTypes;
public sealed override Type[] GenericTypeArguments => Type.EmptyTypes;
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;
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/System.Private.CoreLib/src/System/Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected Type() { }
public virtual int GetArrayRank() => throw new NotSupportedException(SR.NotSupported_SubclassOverride);

public virtual Type GetGenericTypeDefinition() => throw new NotSupportedException(SR.NotSupported_SubclassOverride);
public virtual Type[] GenericTypeArguments => (IsGenericType && !IsGenericTypeDefinition) ? GetGenericArguments() : Array.Empty<Type>();
public virtual Type[] GenericTypeArguments => (IsGenericType && !IsGenericTypeDefinition) ? GetGenericArguments() : Type.EmptyTypes;
public virtual Type[] GetGenericArguments() => throw new NotSupportedException(SR.NotSupported_SubclassOverride);

public virtual int GenericParameterPosition => throw new InvalidOperationException(SR.Arg_NotGenericParameter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ internal static bool IsNonAttributedTypeValidForSerialization(Type type)
else
{
return (type.IsVisible &&
type.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, Array.Empty<Type>()) != null);
type.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, Type.EmptyTypes) != null);
}
}

Expand Down Expand Up @@ -1425,7 +1425,7 @@ internal MethodInfo? GetKeyValuePairMethodInfo
if (type.IsValueType)
return null;

ConstructorInfo? ctor = type.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, Array.Empty<Type>());
ConstructorInfo? ctor = type.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, Type.EmptyTypes);
if (ctor == null)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.NonAttributedSerializableTypesMustHaveDefaultConstructor, DataContract.GetClrTypeFullName(type))));

Expand Down
Loading