this.CopyTo(array, (int)index);
}
+ private static class EmptyArray<T>
+ {
+ internal static readonly T[] Value = new T[0];
+ }
+
[Pure]
public static T[] Empty<T>()
{
}
}
-// Useful in number of places that return an empty byte array to avoid unnecessary memory allocation.
-internal static class EmptyArray<T>
-{
- public static readonly T[] Value = new T[0];
-}
private Object _syncRoot;
private const int _defaultCapacity = 4;
- private static readonly Object[] emptyArray = EmptyArray<Object>.Value;
+ private static readonly Object[] emptyArray = Array.Empty<Object>();
// Constructs a ArrayList. The list is initially empty and has a capacity
// of zero. Upon adding the first element to the list the capacity is
{
get
{
- return EmptyArray<Object>.Value;
+ return Array.Empty<Object>();
}
}
{
get
{
- return EmptyArray<Object>.Value;
+ return Array.Empty<Object>();
}
}
byte [] keyData;
if (source.Length == 0)
{
- keyData = EmptyArray<Byte>.Value;
+ keyData = Array.Empty<Byte>();
}
else
{
if (count == 0)
{
- return EmptyArray<Char>.Value;
+ return Array.Empty<Char>();
}
// SafeCritical: we own the chars buffer, and therefore can guarantee that the index and count are valid
if (count == 0)
{
- return EmptyArray<Byte>.Value;
+ return Array.Empty<Byte>();
}
byte[] result = new byte[count];
}
Contract.EndContractBlock();
- _buffer = capacity != 0 ? new byte[capacity] : EmptyArray<byte>.Value;
+ _buffer = capacity != 0 ? new byte[capacity] : Array.Empty<byte>();
_capacity = capacity;
_expandable = true;
_writable = true;
Contract.Requires(caType != null);
if (type.GetElementType() != null)
- return (caType.IsValueType) ? EmptyArray<Object>.Value : CreateAttributeArrayHelper(caType, 0);
+ return (caType.IsValueType) ? Array.Empty<Object>() : CreateAttributeArrayHelper(caType, 0);
if (type.IsGenericType && !type.IsGenericTypeDefinition)
type = type.GetGenericTypeDefinition() as RuntimeType;
return s_anonymouslyHostedDynamicMethodsModule;
ConstructorInfo transparencyCtor = typeof(SecurityTransparentAttribute).GetConstructor(Type.EmptyTypes);
- CustomAttributeBuilder transparencyAttribute = new CustomAttributeBuilder(transparencyCtor, EmptyArray<Object>.Value);
+ CustomAttributeBuilder transparencyAttribute = new CustomAttributeBuilder(transparencyCtor, Array.Empty<Object>());
List<CustomAttributeBuilder> assemblyAttributes = new List<CustomAttributeBuilder>();
assemblyAttributes.Add(transparencyAttribute);
if (attributeType.IsAssignableFrom(typeof(MethodImplAttribute)))
return new Object[] { new MethodImplAttribute(GetMethodImplementationFlags()) };
else
- return EmptyArray<Object>.Value;
+ return Array.Empty<Object>();
}
public override Object[] GetCustomAttributes(bool inherit)
Object[] ICustomAttributeProvider.GetCustomAttributes(Type attributeType, bool inherit)
{
- return EmptyArray<Object>.Value;
+ return Array.Empty<Object>();
}
Object[] ICustomAttributeProvider.GetCustomAttributes(bool inherit)
{
- return EmptyArray<Object>.Value;
+ return Array.Empty<Object>();
}
bool ICustomAttributeProvider.IsDefined(Type attributeType, bool inherit)
internal override Type[] GetParameterTypes()
{
if (m_parameterTypes == null)
- m_parameterTypes = EmptyArray<Type>.Value;
+ m_parameterTypes = Array.Empty<Type>();
return m_parameterTypes;
}
internal SignatureHelper GetMethodSignature()
{
if (m_parameterTypes == null)
- m_parameterTypes = EmptyArray<Type>.Value;
+ m_parameterTypes = Array.Empty<Type>();
m_signature = SignatureHelper.GetMethodSigHelper(m_module, m_callingConvention, m_inst != null ? m_inst.Length : 0,
m_returnType == null ? typeof(void) : m_returnType, m_returnTypeRequiredCustomModifiers, m_returnTypeOptionalCustomModifiers,
}
else
{
- m_parameterTypes = EmptyArray<Type>.Value;
+ m_parameterTypes = Array.Empty<Type>();
}
m_module = mod;
if (m_typeInterfaces == null)
{
- return EmptyArray<Type>.Value;
+ return Array.Empty<Type>();
}
return m_typeInterfaces.ToArray();
public override Type[] GetRequiredCustomModifiers()
{
- return EmptyArray<Type>.Value;
+ return Array.Empty<Type>();
}
public override Type[] GetOptionalCustomModifiers()
{
- return EmptyArray<Type>.Value;
+ return Array.Empty<Type>();
}
#endregion
if (types == null)
{
- types = EmptyArray<Type>.Value;
+ types = Array.Empty<Type>();
}
return types;
}
public override Object[] GetCustomAttributes(bool inherit)
{
if (MdToken.IsNullToken(m_tkParamDef))
- return EmptyArray<Object>.Value;
+ return Array.Empty<Object>();
return CustomAttribute.GetCustomAttributes(this, typeof(object) as RuntimeType);
}
Contract.EndContractBlock();
if (MdToken.IsNullToken(m_tkParamDef))
- return EmptyArray<Object>.Value;
+ return Array.Empty<Object>();
RuntimeType attributeRuntimeType = attributeType.UnderlyingSystemType as RuntimeType;
public T[] ToArray()
{
if (_count == 0)
- return EmptyArray<T>.Value;
+ return Array.Empty<T>();
if (_count == 1)
return new T[1] { _item };
{
if (ReflectedType.IsGenericParameter)
{
- return EmptyArray<RuntimeConstructorInfo>.Value;
+ return Array.Empty<RuntimeConstructorInfo>();
}
ListBuilder<RuntimeConstructorInfo> list = new ListBuilder<RuntimeConstructorInfo>();
// For example, TypeDescs do not have metadata tokens
if (MdToken.IsNullToken(tkEnclosingType))
- return EmptyArray<RuntimeType>.Value;
+ return Array.Empty<RuntimeType>();
ListBuilder<RuntimeType> list = new ListBuilder<RuntimeType>();
Type[] types = GetRootElementType().GetTypeHandleInternal().GetInstantiationPublic();
if (types == null)
- types = EmptyArray<Type>.Value;
+ types = Array.Empty<Type>();
return types;
}
Type[] constraints = new RuntimeTypeHandle(this).GetConstraints();
if (constraints == null)
- constraints = EmptyArray<Type>.Value;
+ constraints = Array.Empty<Type>();
return constraints;
}
}
if (members == null)
- members = EmptyArray<MemberInfo>.Value;
+ members = Array.Empty<MemberInfo>();
return members;
}
finalists = new MethodInfo[] { finalist };
if (providedArgs == null)
- providedArgs = EmptyArray<Object>.Value;
+ providedArgs = Array.Empty<Object>();
Object state = null;
Object server = null;
if (args == null)
- args = EmptyArray<Object>.Value;
+ args = Array.Empty<Object>();
int argCnt = args.Length;
if ((count == 0) || (omitEmptyEntries && this.Length == 0))
{
- return EmptyArray<String>.Value;
+ return Array.Empty<String>();
}
if (count == 1)
if ((count == 0) || (omitEmptyEntries && this.Length == 0))
{
- return EmptyArray<String>.Value;
+ return Array.Empty<String>();
}
if (count == 1 || (singleSeparator && separator.Length == 0))
[Pure]
public virtual byte[] GetPreamble()
{
- return EmptyArray<Byte>.Value;
+ return Array.Empty<Byte>();
}
private void GetDataItem()
internal virtual char[] GetBestFitUnicodeToBytesData()
{
// Normally we don't have any best fit data.
- return EmptyArray<Char>.Value;
+ return Array.Empty<Char>();
}
internal virtual char[] GetBestFitBytesToUnicodeData()
{
// Normally we don't have any best fit data.
- return EmptyArray<Char>.Value;
+ return Array.Empty<Char>();
}
internal void ThrowBytesOverflow()