<Rule Id="CA1820" Action="None" /> <!-- Test for empty strings using string length -->
<Rule Id="CA1822" Action="None" /> <!-- Mark members as static -->
<Rule Id="CA1823" Action="None" /> <!-- Avoid unused private fields -->
- <Rule Id="CA1825" Action="None" /> <!-- Avoid zero-length array allocations. -->
<Rule Id="CA2000" Action="None" /> <!-- Dispose objects before losing scope -->
<Rule Id="CA2010" Action="None" /> <!-- Always consume the value returned by methods marked with PreserveSigAttribute -->
<Rule Id="CA2100" Action="None" /> <!-- Review SQL queries for security vulnerabilities -->
{
ThrowIfDeserializationInProgressWithSwitchDel throwIfDeserializationInProgressDelegate = null;
MethodInfo throwMethod = typeof(SerializationInfo).GetMethod("ThrowIfDeserializationInProgress",
- BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public, null, new Type[] { typeof(string), typeof(int).MakeByRefType() }, new ParameterModifier[0]);
+ BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public, null, new Type[] { typeof(string), typeof(int).MakeByRefType() }, Array.Empty<ParameterModifier>());
if (throwMethod != null)
{
return result;
}
}
- return new KeyValuePair<string, object>[0];
+ return Array.Empty<KeyValuePair<string, object>>();
}
[Serializable]
/// <summary>
/// An empty (initialized) instance of <see cref="ImmutableArray{T}"/>.
/// </summary>
+#pragma warning disable CA1825 // Array.Empty<T>() doesn't exist in all configurations
public static readonly ImmutableArray<T> Empty = new ImmutableArray<T>(new T[0]);
+#pragma warning restore CA1825
/// <summary>
/// The backing field for this instance. References to this value should never be shared with outside code.
bindings.DangerousRelease();
}
}
- return ((null != value) ? value : new byte[0]);
+ return ((null != value) ? value : Array.Empty<byte>());
}
private void Value_ByRefBYTES(Byte[] value)
{
// the return value gets marked as an output parameter.
static private OleDbParameter[] DeriveParametersFromStoredProcedure(OleDbConnection connection, OleDbCommand command)
{
- OleDbParameter[] plist = new OleDbParameter[0];
+ OleDbParameter[] plist = Array.Empty<OleDbParameter>();
if (connection.SupportSchemaRowset(OleDbSchemaGuid.Procedure_Parameters))
{
{
if (null == restrictions)
{
- restrictions = new object[0];
+ restrictions = Array.Empty<object>();
}
DataTable dataTable = null;
using (IDBSchemaRowsetWrapper wrapper = IDBSchemaRowset())
if (null == propertySets)
{
- propertySets = new Guid[0];
+ propertySets = Array.Empty<Guid>();
}
using (PropertyIDSet propidset = new PropertyIDSet(propertySets))
{
{
_hasRows = false;
_visibleFieldCount = 0;
- _metadata = new MetaData[0];
+ _metadata = Array.Empty<MetaData>();
}
}
/// </summary>
public partial class Activity
{
- private static readonly IEnumerable<KeyValuePair<string, string>> s_emptyBaggageTags = new KeyValuePair<string, string>[0]; // Array.Empty<T>() doesn't exist in all configurations
+#pragma warning disable CA1825 // Array.Empty<T>() doesn't exist in all configurations
+ private static readonly IEnumerable<KeyValuePair<string, string>> s_emptyBaggageTags = new KeyValuePair<string, string>[0];
+#pragma warning restore CA1825
private const byte ActivityTraceFlagsIsSet = 0b_1_0000000; // Internal flag to indicate if flags have been set
private const int RequestIdMaxLength = 1024;
return this.FormatDescription();
// Copy the value IEnumerable to an array.
- string[] theValues = new string[0];
+ string[] theValues = Array.Empty<string>();
int i = 0;
foreach (object o in values)
{
case (int)UnsafeNativeMethods.EvtVariantType.EvtVarTypeBinary:
case ((int)UnsafeNativeMethods.EvtMasks.EVT_VARIANT_TYPE_ARRAY | (int)UnsafeNativeMethods.EvtVariantType.EvtVarTypeByte):
if (val.Reference == IntPtr.Zero)
- return new Byte[0];
+ return Array.Empty<byte>();
Byte[] arByte = new Byte[val.Count];
Marshal.Copy(val.Reference, arByte, 0, (int)val.Count);
return arByte;
case ((int)UnsafeNativeMethods.EvtMasks.EVT_VARIANT_TYPE_ARRAY | (int)UnsafeNativeMethods.EvtVariantType.EvtVarTypeInt16):
if (val.Reference == IntPtr.Zero)
- return new Int16[0];
+ return Array.Empty<short>();
Int16[] arInt16 = new Int16[val.Count];
Marshal.Copy(val.Reference, arInt16, 0, (int)val.Count);
return arInt16;
case ((int)UnsafeNativeMethods.EvtMasks.EVT_VARIANT_TYPE_ARRAY | (int)UnsafeNativeMethods.EvtVariantType.EvtVarTypeInt32):
if (val.Reference == IntPtr.Zero)
- return new Int32[0];
+ return Array.Empty<int>();
Int32[] arInt32 = new Int32[val.Count];
Marshal.Copy(val.Reference, arInt32, 0, (int)val.Count);
return arInt32;
case ((int)UnsafeNativeMethods.EvtMasks.EVT_VARIANT_TYPE_ARRAY | (int)UnsafeNativeMethods.EvtVariantType.EvtVarTypeInt64):
if (val.Reference == IntPtr.Zero)
- return new Int64[0];
+ return Array.Empty<long>();
Int64[] arInt64 = new Int64[val.Count];
Marshal.Copy(val.Reference, arInt64, 0, (int)val.Count);
return arInt64;
case ((int)UnsafeNativeMethods.EvtMasks.EVT_VARIANT_TYPE_ARRAY | (int)UnsafeNativeMethods.EvtVariantType.EvtVarTypeSingle):
if (val.Reference == IntPtr.Zero)
- return new Single[0];
+ return Array.Empty<float>();
Single[] arSingle = new Single[val.Count];
Marshal.Copy(val.Reference, arSingle, 0, (int)val.Count);
return arSingle;
case ((int)UnsafeNativeMethods.EvtMasks.EVT_VARIANT_TYPE_ARRAY | (int)UnsafeNativeMethods.EvtVariantType.EvtVarTypeDouble):
if (val.Reference == IntPtr.Zero)
- return new Double[0];
+ return Array.Empty<double>();
Double[] arDouble = new Double[val.Count];
Marshal.Copy(val.Reference, arDouble, 0, (int)val.Count);
return arDouble;
IntPtr ptr = val.Reference;
if (ptr == IntPtr.Zero)
{
- return new bool[0];
+ return Array.Empty<bool>();
}
else
{
IntPtr ptr = val.Reference;
if (ptr == IntPtr.Zero)
{
- return new DateTime[0];
+ return Array.Empty<DateTime>();
}
else
{
IntPtr ptr = val.Reference;
if (ptr == IntPtr.Zero)
{
- return new DateTime[0];
+ return Array.Empty<DateTime>();
}
else
{
{
if (val.Reference == IntPtr.Zero)
{
- return new string[0];
+ return Array.Empty<string>();
}
else
{
private delegate DynamicMetaObject Fallback<TBinder>(MetaDynamic @this, TBinder binder, DynamicMetaObject errorSuggestion);
- private static readonly Expression[] s_noArgs = new Expression[0]; // used in reference comparison, requires unique object identity
+#pragma warning disable CA1825 // used in reference comparison, requires unique object identity
+ private static readonly Expression[] s_noArgs = new Expression[0];
+#pragma warning restore CA1825
private static ReadOnlyCollection<Expression> GetConvertedArgs(params Expression[] args)
{
//
internal class NegoState
{
- private static readonly byte[] s_emptyMessage = new byte[0]; // used in reference comparisons
+#pragma warning disable CA1825 // used in reference comparison, requires unique object identity
+ private static readonly byte[] s_emptyMessage = new byte[0];
+#pragma warning restore CA1825
private static readonly AsyncCallback s_readCallback = new AsyncCallback(ReadCallback);
private static readonly AsyncCallback s_writeCallback = new AsyncCallback(WriteCallback);
}
}
- private static readonly object[] s_nullparams = { };
-
private XmlNode GetNode(XPathNavigator n)
{
IHasXmlNode iHasNode = (IHasXmlNode)n;
{
internal static class EmptyArray<T>
{
+#pragma warning disable CA1825 // Array.Empty<T>() doesn't exist in all configurations
internal static readonly T[] Instance = new T[0];
+#pragma warning restore CA1825
}
}
public abstract class TextEncoder
{
// Fast cache for Ascii
- private static readonly byte[] s_noEscape = new byte[] { }; // Should not be Array.Empty<byte> since used as a singleton for comparison.
+#pragma warning disable CA1825 // should not be Array.Empty<byte> as this is used as a singleton for comparisons
+ private static readonly byte[] s_noEscape = new byte[] { };
+#pragma warning restore CA1825
private byte[][] _asciiEscape = new byte[0x80][];
// The following pragma disables a warning complaining about non-CLS compliant members being abstract,
Type.EmptyTypes,
modifiers: null);
- ImmutableCollectionCreator creator = (ImmutableCollectionCreator)constructor.Invoke(new object[] { });
+ ImmutableCollectionCreator creator = (ImmutableCollectionCreator)constructor.Invoke(Array.Empty<object>());
creator.RegisterCreatorDelegateFromMethod(createRange);
return creator;
}
Type.EmptyTypes,
modifiers: null);
- ImmutableCollectionCreator creator = (ImmutableCollectionCreator)constructor.Invoke(new object[] { });
+ ImmutableCollectionCreator creator = (ImmutableCollectionCreator)constructor.Invoke(Array.Empty<object>());
creator.RegisterCreatorDelegateFromMethod(createRange);
return creator;
}
internal readonly struct ImmutableArray<T>
{
/// <summary>An empty array.</summary>
+#pragma warning disable CA1825 // Array.Empty<T>() doesn't exist in all configurations
private static readonly ImmutableArray<T> s_empty = new ImmutableArray<T>(new T[0]);
+#pragma warning restore CA1825
/// <summary>The immutable data in this array instance.</summary>
private readonly T[] _array;