From 1b45ed38a21527dc87bb698a231a5b877772a04c Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Wed, 18 Jan 2023 12:32:59 +0100 Subject: [PATCH] Analyzer fixes --- NuGet.config | 1 + eng/Versions.props | 4 ++-- .../TrimAnalysis/ParameterProxy.cs | 2 +- src/ILLink.Shared/DataFlow/DefaultValueDictionary.cs | 4 ++-- src/ILLink.Shared/DataFlow/MaybeLattice.cs | 4 ++-- src/ILLink.Shared/DataFlow/ValueSet.cs | 4 ++-- src/linker/Linker.Dataflow/HoistedLocalKey.cs | 4 ++-- src/linker/Linker.Dataflow/ValueNode.cs | 4 ++-- src/linker/Linker/LinkerAttributesInformation.cs | 2 +- .../Verifiers/CSharpAnalyzerVerifier`1.cs | 4 +--- .../ExpectedInstructionSequenceAttribute.cs | 3 +-- ...InstructionSequenceOnMemberInAssemblyAttribute.cs | 9 +++------ .../Assertions/ExpectedLocalsSequenceAttribute.cs | 6 ++---- .../Assertions/IgnoreTestCaseAttribute.cs | 3 +-- .../Assertions/KeptAttributeAttribute.cs | 3 +-- .../KeptAttributeOnFixedBufferTypeAttribute.cs | 3 +-- .../Assertions/KeptBaseOnTypeInAssemblyAttribute.cs | 3 +-- .../Assertions/KeptBaseTypeAttribute.cs | 9 +++------ .../Assertions/KeptExportedTypeAttribute.cs | 3 +-- .../Assertions/KeptInitializerData.cs | 3 +-- .../Assertions/KeptInterfaceAttribute.cs | 9 +++------ .../KeptInterfaceOnTypeInAssemblyAttribute.cs | 3 +-- .../Assertions/KeptMemberInAssemblyAttribute.cs | 12 ++++-------- .../Assertions/KeptOverrideAttribute.cs | 3 +-- .../Assertions/KeptReferencesInAssemblyAttribute.cs | 3 +-- .../Assertions/KeptSecurityAttribute.cs | 3 +-- .../Assertions/KeptTypeInAssemblyAttribute.cs | 3 +-- .../RemovedInterfaceOnTypeInAssemblyAttribute.cs | 3 +-- .../Assertions/RemovedMemberInAssemblyAttribute.cs | 12 ++++-------- .../Assertions/RemovedTypeInAssemblyAttribute.cs | 3 +-- .../Assertions/TestCaseRequirementsAttribute.cs | 3 +-- .../Metadata/SetupCompileAfterAttribute.cs | 3 +-- .../Metadata/SetupCompileBeforeAttribute.cs | 6 ++---- test/Mono.Linker.Tests/Extensions/NiceIO.cs | 3 +-- 34 files changed, 54 insertions(+), 93 deletions(-) diff --git a/NuGet.config b/NuGet.config index e50a0328b5ff..3ea744d29733 100644 --- a/NuGet.config +++ b/NuGet.config @@ -6,6 +6,7 @@ + diff --git a/eng/Versions.props b/eng/Versions.props index 385f85158aae..6011549f0f43 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -25,8 +25,8 @@ $(MicrosoftCodeAnalysisVersion) 1.0.1-beta1.* 3.3.2 - 7.0.0-preview1.22513.1 - 7.0.0-preview.7.22375.6 + 8.0.0-preview1.22566.1 + 8.0.0-alpha.1.23067.11 diff --git a/src/ILLink.RoslynAnalyzer/TrimAnalysis/ParameterProxy.cs b/src/ILLink.RoslynAnalyzer/TrimAnalysis/ParameterProxy.cs index fe01aeaf5187..27b47d4f3b4e 100644 --- a/src/ILLink.RoslynAnalyzer/TrimAnalysis/ParameterProxy.cs +++ b/src/ILLink.RoslynAnalyzer/TrimAnalysis/ParameterProxy.cs @@ -11,7 +11,7 @@ partial struct ParameterProxy { public ParameterProxy (IParameterSymbol parameter) { - Method = (new ((IMethodSymbol) parameter.ContainingSymbol)); + Method = new ((IMethodSymbol) parameter.ContainingSymbol); Index = (ParameterIndex) parameter.Ordinal + (Method.HasImplicitThis () ? 1 : 0); } diff --git a/src/ILLink.Shared/DataFlow/DefaultValueDictionary.cs b/src/ILLink.Shared/DataFlow/DefaultValueDictionary.cs index 4d411206cd87..0c2ce21ad670 100644 --- a/src/ILLink.Shared/DataFlow/DefaultValueDictionary.cs +++ b/src/ILLink.Shared/DataFlow/DefaultValueDictionary.cs @@ -109,7 +109,7 @@ public DefaultValueDictionary Clone () // This type should never be used as a dictionary key. public override int GetHashCode () => throw new NotImplementedException (); - public static bool operator ==(DefaultValueDictionary left, DefaultValueDictionary right) => left.Equals(right); - public static bool operator !=(DefaultValueDictionary left, DefaultValueDictionary right) => !(left == right); + public static bool operator == (DefaultValueDictionary left, DefaultValueDictionary right) => left.Equals (right); + public static bool operator != (DefaultValueDictionary left, DefaultValueDictionary right) => !(left == right); } } diff --git a/src/ILLink.Shared/DataFlow/MaybeLattice.cs b/src/ILLink.Shared/DataFlow/MaybeLattice.cs index caeb913ae4fb..6c2e6d60309c 100644 --- a/src/ILLink.Shared/DataFlow/MaybeLattice.cs +++ b/src/ILLink.Shared/DataFlow/MaybeLattice.cs @@ -27,8 +27,8 @@ public Maybe Clone () return new (value); } - public static bool operator ==(Maybe left, Maybe right) => left.Equals(right); - public static bool operator !=(Maybe left, Maybe right) => !(left == right); + public static bool operator == (Maybe left, Maybe right) => left.Equals (right); + public static bool operator != (Maybe left, Maybe right) => !(left == right); } public struct MaybeLattice : ILattice> diff --git a/src/ILLink.Shared/DataFlow/ValueSet.cs b/src/ILLink.Shared/DataFlow/ValueSet.cs index d6cae4af155d..d4d5af4a362c 100644 --- a/src/ILLink.Shared/DataFlow/ValueSet.cs +++ b/src/ILLink.Shared/DataFlow/ValueSet.cs @@ -120,8 +120,8 @@ public bool Equals (ValueSet other) } } - public static bool operator ==(ValueSet left, ValueSet right) => left.Equals(right); - public static bool operator !=(ValueSet left, ValueSet right) => !(left == right); + public static bool operator == (ValueSet left, ValueSet right) => left.Equals (right); + public static bool operator != (ValueSet left, ValueSet right) => !(left == right); public override int GetHashCode () { diff --git a/src/linker/Linker.Dataflow/HoistedLocalKey.cs b/src/linker/Linker.Dataflow/HoistedLocalKey.cs index 74aeebe11937..503bdc6bbb84 100644 --- a/src/linker/Linker.Dataflow/HoistedLocalKey.cs +++ b/src/linker/Linker.Dataflow/HoistedLocalKey.cs @@ -27,7 +27,7 @@ public HoistedLocalKey (FieldDefinition field) public override int GetHashCode () => Field.GetHashCode (); - public static bool operator ==(HoistedLocalKey left, HoistedLocalKey right) => left.Equals(right); - public static bool operator !=(HoistedLocalKey left, HoistedLocalKey right) => !(left == right); + public static bool operator == (HoistedLocalKey left, HoistedLocalKey right) => left.Equals (right); + public static bool operator != (HoistedLocalKey left, HoistedLocalKey right) => !(left == right); } } \ No newline at end of file diff --git a/src/linker/Linker.Dataflow/ValueNode.cs b/src/linker/Linker.Dataflow/ValueNode.cs index 453069c3f4d9..3374ca3317af 100644 --- a/src/linker/Linker.Dataflow/ValueNode.cs +++ b/src/linker/Linker.Dataflow/ValueNode.cs @@ -65,7 +65,7 @@ public ValueBasicBlockPair (MultiValue value, int basicBlockIndex) public override int GetHashCode () => HashUtils.Combine (Value.GetHashCode (), BasicBlockIndex); - public static bool operator ==(ValueBasicBlockPair left, ValueBasicBlockPair right) => left.Equals(right); - public static bool operator !=(ValueBasicBlockPair left, ValueBasicBlockPair right) => !(left == right); + public static bool operator == (ValueBasicBlockPair left, ValueBasicBlockPair right) => left.Equals (right); + public static bool operator != (ValueBasicBlockPair left, ValueBasicBlockPair right) => !(left == right); } } diff --git a/src/linker/Linker/LinkerAttributesInformation.cs b/src/linker/Linker/LinkerAttributesInformation.cs index 9fef9b59cdeb..3daeb136f11d 100644 --- a/src/linker/Linker/LinkerAttributesInformation.cs +++ b/src/linker/Linker/LinkerAttributesInformation.cs @@ -106,7 +106,7 @@ public IEnumerable GetAttributes () where T : Attribute return attributeList.Cast (); } - static Attribute? ProcessRequiresUnreferencedCodeAttribute (LinkContext context, ICustomAttributeProvider provider, CustomAttribute customAttribute) + static RequiresUnreferencedCodeAttribute? ProcessRequiresUnreferencedCodeAttribute (LinkContext context, ICustomAttributeProvider provider, CustomAttribute customAttribute) { if (!(provider is MethodDefinition || provider is TypeDefinition)) return null; diff --git a/test/ILLink.RoslynAnalyzer.Tests/Verifiers/CSharpAnalyzerVerifier`1.cs b/test/ILLink.RoslynAnalyzer.Tests/Verifiers/CSharpAnalyzerVerifier`1.cs index 17e3a1fa27b7..32f60660d3fd 100644 --- a/test/ILLink.RoslynAnalyzer.Tests/Verifiers/CSharpAnalyzerVerifier`1.cs +++ b/test/ILLink.RoslynAnalyzer.Tests/Verifiers/CSharpAnalyzerVerifier`1.cs @@ -585,9 +585,7 @@ static bool IsMessageMatch (Diagnostic actual, ImmutableArray actualArgu public MatchQuality (int value) { - if (value < 0) { - throw new ArgumentOutOfRangeException (nameof (value)); - } + ArgumentOutOfRangeException.ThrowIfNegative (value); _value = value; } diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedInstructionSequenceAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedInstructionSequenceAttribute.cs index 35ead6966a4f..101e1be0288c 100644 --- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedInstructionSequenceAttribute.cs +++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedInstructionSequenceAttribute.cs @@ -10,8 +10,7 @@ public class ExpectedInstructionSequenceAttribute : BaseInAssemblyAttribute { public ExpectedInstructionSequenceAttribute (string[] opCodes) { - if (opCodes == null) - throw new ArgumentNullException (nameof (opCodes)); + ArgumentNullException.ThrowIfNull (opCodes); } } } \ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedInstructionSequenceOnMemberInAssemblyAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedInstructionSequenceOnMemberInAssemblyAttribute.cs index 899b979c5211..124bbab5bac7 100644 --- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedInstructionSequenceOnMemberInAssemblyAttribute.cs +++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedInstructionSequenceOnMemberInAssemblyAttribute.cs @@ -12,12 +12,10 @@ public ExpectedInstructionSequenceOnMemberInAssemblyAttribute (string assemblyFi { if (string.IsNullOrEmpty (assemblyFileName)) throw new ArgumentNullException (nameof (assemblyFileName)); - if (type == null) - throw new ArgumentNullException (nameof (type)); + ArgumentNullException.ThrowIfNull (type); if (string.IsNullOrEmpty (memberName)) throw new ArgumentNullException (nameof (memberName)); - if (opCodes == null) - throw new ArgumentNullException (nameof (opCodes)); + ArgumentNullException.ThrowIfNull (opCodes); } public ExpectedInstructionSequenceOnMemberInAssemblyAttribute (string assemblyFileName, string typeName, string memberName, string[] opCodes) @@ -28,8 +26,7 @@ public ExpectedInstructionSequenceOnMemberInAssemblyAttribute (string assemblyFi throw new ArgumentNullException (nameof (typeName)); if (string.IsNullOrEmpty (memberName)) throw new ArgumentNullException (nameof (memberName)); - if (opCodes == null) - throw new ArgumentNullException (nameof (opCodes)); + ArgumentNullException.ThrowIfNull (opCodes); } } } \ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedLocalsSequenceAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedLocalsSequenceAttribute.cs index fdd3441b71f4..2016d26a0dbd 100644 --- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedLocalsSequenceAttribute.cs +++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedLocalsSequenceAttribute.cs @@ -10,14 +10,12 @@ public class ExpectedLocalsSequenceAttribute : BaseInAssemblyAttribute { public ExpectedLocalsSequenceAttribute (string[] types) { - if (types == null) - throw new ArgumentNullException (nameof (types)); + ArgumentNullException.ThrowIfNull (types); } public ExpectedLocalsSequenceAttribute (Type[] types) { - if (types == null) - throw new ArgumentNullException (nameof (types)); + ArgumentNullException.ThrowIfNull (types); } } } \ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/IgnoreTestCaseAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/IgnoreTestCaseAttribute.cs index 78fd0e453742..a9b11ebd3f32 100644 --- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/IgnoreTestCaseAttribute.cs +++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/IgnoreTestCaseAttribute.cs @@ -11,8 +11,7 @@ public class IgnoreTestCaseAttribute : Attribute public IgnoreTestCaseAttribute (string reason) { - if (reason == null) - throw new ArgumentNullException (nameof (reason)); + ArgumentNullException.ThrowIfNull (reason); } } } \ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptAttributeAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptAttributeAttribute.cs index 0b5943a5a1a5..e558f304720a 100644 --- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptAttributeAttribute.cs +++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptAttributeAttribute.cs @@ -17,8 +17,7 @@ public KeptAttributeAttribute (string attributeName) public KeptAttributeAttribute (Type type) { - if (type == null) - throw new ArgumentNullException (nameof (type)); + ArgumentNullException.ThrowIfNull (type); } } } diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptAttributeOnFixedBufferTypeAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptAttributeOnFixedBufferTypeAttribute.cs index 0fc56741a8ca..559e81bdad16 100644 --- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptAttributeOnFixedBufferTypeAttribute.cs +++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptAttributeOnFixedBufferTypeAttribute.cs @@ -16,8 +16,7 @@ public KeptAttributeOnFixedBufferTypeAttribute (string attributeName) public KeptAttributeOnFixedBufferTypeAttribute (Type type) { - if (type == null) - throw new ArgumentNullException (nameof (type)); + ArgumentNullException.ThrowIfNull (type); } } } \ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptBaseOnTypeInAssemblyAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptBaseOnTypeInAssemblyAttribute.cs index acac5d575bbc..5d454d806eec 100644 --- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptBaseOnTypeInAssemblyAttribute.cs +++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptBaseOnTypeInAssemblyAttribute.cs @@ -10,8 +10,7 @@ public class KeptBaseOnTypeInAssemblyAttribute : BaseInAssemblyAttribute { public KeptBaseOnTypeInAssemblyAttribute (string assemblyFileName, Type type, string baseAssemblyFileName, Type baseType) { - if (type == null) - throw new ArgumentNullException (nameof (type)); + ArgumentNullException.ThrowIfNull (type); if (string.IsNullOrEmpty (assemblyFileName)) throw new ArgumentException ("Value cannot be null or empty.", nameof (assemblyFileName)); diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptBaseTypeAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptBaseTypeAttribute.cs index c4e4a2488954..c98ad9abcbe3 100644 --- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptBaseTypeAttribute.cs +++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptBaseTypeAttribute.cs @@ -10,16 +10,13 @@ public sealed class KeptBaseTypeAttribute : KeptAttribute { public KeptBaseTypeAttribute (Type baseType) { - if (baseType == null) - throw new ArgumentNullException (nameof (baseType)); + ArgumentNullException.ThrowIfNull (baseType); } public KeptBaseTypeAttribute (Type baseType, params object[] typeArguments) { - if (baseType == null) - throw new ArgumentNullException (nameof (baseType)); - if (typeArguments == null) - throw new ArgumentNullException (nameof (typeArguments)); + ArgumentNullException.ThrowIfNull (baseType); + ArgumentNullException.ThrowIfNull (typeArguments); } } } \ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptExportedTypeAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptExportedTypeAttribute.cs index 76dbe921c945..2e4ba1903e1a 100644 --- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptExportedTypeAttribute.cs +++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptExportedTypeAttribute.cs @@ -13,8 +13,7 @@ public class KeptExportedTypeAttribute : KeptAttribute { public KeptExportedTypeAttribute (Type type) { - if (type is null) - throw new ArgumentNullException (nameof (type)); + ArgumentNullException.ThrowIfNull (type); } } } diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptInitializerData.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptInitializerData.cs index 25b8c8261f16..9b98ef46e451 100644 --- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptInitializerData.cs +++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptInitializerData.cs @@ -15,8 +15,7 @@ public KeptInitializerData () public KeptInitializerData (int occurrenceIndexInBody) { - if (occurrenceIndexInBody < 0) - throw new ArgumentOutOfRangeException (nameof (occurrenceIndexInBody)); + ArgumentOutOfRangeException.ThrowIfNegative (occurrenceIndexInBody); } } } \ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptInterfaceAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptInterfaceAttribute.cs index 85279abcd83f..abbf5784e99b 100644 --- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptInterfaceAttribute.cs +++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptInterfaceAttribute.cs @@ -11,16 +11,13 @@ public class KeptInterfaceAttribute : KeptAttribute public KeptInterfaceAttribute (Type interfaceType) { - if (interfaceType == null) - throw new ArgumentNullException (nameof (interfaceType)); + ArgumentNullException.ThrowIfNull (interfaceType); } public KeptInterfaceAttribute (Type interfaceType, params object[] typeArguments) { - if (interfaceType == null) - throw new ArgumentNullException (nameof (interfaceType)); - if (typeArguments == null) - throw new ArgumentNullException (nameof (typeArguments)); + ArgumentNullException.ThrowIfNull (interfaceType); + ArgumentNullException.ThrowIfNull (typeArguments); } } } \ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptInterfaceOnTypeInAssemblyAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptInterfaceOnTypeInAssemblyAttribute.cs index 2741439facc8..88bfd654ad75 100644 --- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptInterfaceOnTypeInAssemblyAttribute.cs +++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptInterfaceOnTypeInAssemblyAttribute.cs @@ -10,8 +10,7 @@ public class KeptInterfaceOnTypeInAssemblyAttribute : BaseInAssemblyAttribute { public KeptInterfaceOnTypeInAssemblyAttribute (string assemblyFileName, Type type, string interfaceAssemblyFileName, Type interfaceType) { - if (type == null) - throw new ArgumentNullException (nameof (type)); + ArgumentNullException.ThrowIfNull (type); if (string.IsNullOrEmpty (assemblyFileName)) throw new ArgumentException ("Value cannot be null or empty.", nameof (assemblyFileName)); diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptMemberInAssemblyAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptMemberInAssemblyAttribute.cs index b8e38f5788c0..a756d8d24704 100644 --- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptMemberInAssemblyAttribute.cs +++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptMemberInAssemblyAttribute.cs @@ -13,20 +13,16 @@ public KeptMemberInAssemblyAttribute (string assemblyFileName, Type type, params { if (string.IsNullOrEmpty (assemblyFileName)) throw new ArgumentNullException (nameof (assemblyFileName)); - if (type == null) - throw new ArgumentNullException (nameof (type)); - if (memberNames == null) - throw new ArgumentNullException (nameof (memberNames)); + ArgumentNullException.ThrowIfNull (type); + ArgumentNullException.ThrowIfNull (memberNames); } public KeptMemberInAssemblyAttribute (string assemblyFileName, string typeName, params string[] memberNames) { if (string.IsNullOrEmpty (assemblyFileName)) throw new ArgumentNullException (nameof (assemblyFileName)); - if (typeName == null) - throw new ArgumentNullException (nameof (typeName)); - if (memberNames == null) - throw new ArgumentNullException (nameof (memberNames)); + ArgumentNullException.ThrowIfNull (typeName); + ArgumentNullException.ThrowIfNull (memberNames); } public string ExpectationAssemblyName { get; set; } diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptOverrideAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptOverrideAttribute.cs index 62bfd0c15794..3c02278ea914 100644 --- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptOverrideAttribute.cs +++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptOverrideAttribute.cs @@ -19,8 +19,7 @@ public class KeptOverrideAttribute : KeptAttribute public KeptOverrideAttribute (Type typeWithOverriddenMethod) { - if (typeWithOverriddenMethod == null) - throw new ArgumentNullException (nameof (typeWithOverriddenMethod)); + ArgumentNullException.ThrowIfNull (typeWithOverriddenMethod); TypeWithOverriddenMethodDeclaration = typeWithOverriddenMethod; } } diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptReferencesInAssemblyAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptReferencesInAssemblyAttribute.cs index 0265b9f3a40d..e046c3935df9 100644 --- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptReferencesInAssemblyAttribute.cs +++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptReferencesInAssemblyAttribute.cs @@ -13,8 +13,7 @@ public KeptReferencesInAssemblyAttribute (string assemblyFileName, string[] expe if (string.IsNullOrEmpty (assemblyFileName)) throw new ArgumentNullException (nameof (assemblyFileName)); - if (expectedReferenceAssemblyNames == null) - throw new ArgumentNullException (nameof (expectedReferenceAssemblyNames)); + ArgumentNullException.ThrowIfNull (expectedReferenceAssemblyNames); } } } \ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptSecurityAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptSecurityAttribute.cs index 05519377252d..828bc4b64a0c 100644 --- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptSecurityAttribute.cs +++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptSecurityAttribute.cs @@ -16,8 +16,7 @@ public KeptSecurityAttribute (string attributeName) public KeptSecurityAttribute (Type type) { - if (type == null) - throw new ArgumentNullException (nameof (type)); + ArgumentNullException.ThrowIfNull (type); } } } diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptTypeInAssemblyAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptTypeInAssemblyAttribute.cs index 5be0adc4aa10..a9eb31c5bc81 100644 --- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptTypeInAssemblyAttribute.cs +++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptTypeInAssemblyAttribute.cs @@ -10,8 +10,7 @@ public class KeptTypeInAssemblyAttribute : BaseInAssemblyAttribute { public KeptTypeInAssemblyAttribute (string assemblyFileName, Type type) { - if (type == null) - throw new ArgumentNullException (nameof (type)); + ArgumentNullException.ThrowIfNull (type); if (string.IsNullOrEmpty (assemblyFileName)) throw new ArgumentException ("Value cannot be null or empty.", nameof (assemblyFileName)); } diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/RemovedInterfaceOnTypeInAssemblyAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/RemovedInterfaceOnTypeInAssemblyAttribute.cs index 70465fc3d603..a733a9a18008 100644 --- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/RemovedInterfaceOnTypeInAssemblyAttribute.cs +++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/RemovedInterfaceOnTypeInAssemblyAttribute.cs @@ -10,8 +10,7 @@ public class RemovedInterfaceOnTypeInAssemblyAttribute : BaseInAssemblyAttribute { public RemovedInterfaceOnTypeInAssemblyAttribute (string assemblyFileName, Type type, string interfaceAssemblyFileName, Type interfaceType) { - if (type == null) - throw new ArgumentNullException (nameof (type)); + ArgumentNullException.ThrowIfNull (type); if (string.IsNullOrEmpty (assemblyFileName)) throw new ArgumentException ("Value cannot be null or empty.", nameof (assemblyFileName)); diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/RemovedMemberInAssemblyAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/RemovedMemberInAssemblyAttribute.cs index fe0deb6374aa..bd54db71ba81 100644 --- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/RemovedMemberInAssemblyAttribute.cs +++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/RemovedMemberInAssemblyAttribute.cs @@ -13,20 +13,16 @@ public RemovedMemberInAssemblyAttribute (string assemblyFileName, Type type, par { if (string.IsNullOrEmpty (assemblyFileName)) throw new ArgumentNullException (nameof (assemblyFileName)); - if (type == null) - throw new ArgumentNullException (nameof (type)); - if (memberNames == null) - throw new ArgumentNullException (nameof (memberNames)); + ArgumentNullException.ThrowIfNull (type); + ArgumentNullException.ThrowIfNull (memberNames); } public RemovedMemberInAssemblyAttribute (string assemblyFileName, string typeName, params string[] memberNames) { if (string.IsNullOrEmpty (assemblyFileName)) throw new ArgumentNullException (nameof (assemblyFileName)); - if (typeName == null) - throw new ArgumentNullException (nameof (typeName)); - if (memberNames == null) - throw new ArgumentNullException (nameof (memberNames)); + ArgumentNullException.ThrowIfNull (typeName); + ArgumentNullException.ThrowIfNull (memberNames); } } } diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/RemovedTypeInAssemblyAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/RemovedTypeInAssemblyAttribute.cs index 079ba5d1f0b7..fe98db51bfc0 100644 --- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/RemovedTypeInAssemblyAttribute.cs +++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/RemovedTypeInAssemblyAttribute.cs @@ -10,8 +10,7 @@ public class RemovedTypeInAssemblyAttribute : BaseInAssemblyAttribute { public RemovedTypeInAssemblyAttribute (string assemblyFileName, Type type) { - if (type == null) - throw new ArgumentNullException (nameof (type)); + ArgumentNullException.ThrowIfNull (type); if (string.IsNullOrEmpty (assemblyFileName)) throw new ArgumentException ("Value cannot be null or empty.", nameof (assemblyFileName)); } diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/TestCaseRequirementsAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/TestCaseRequirementsAttribute.cs index 9e766c9ce05c..caf60a23abe0 100644 --- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/TestCaseRequirementsAttribute.cs +++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/TestCaseRequirementsAttribute.cs @@ -10,8 +10,7 @@ public class TestCaseRequirementsAttribute : BaseExpectedLinkedBehaviorAttribute { public TestCaseRequirementsAttribute (TestRunCharacteristics targetFrameworkCharacteristics, string reason) { - if (reason == null) - throw new ArgumentNullException (nameof (reason)); + ArgumentNullException.ThrowIfNull (reason); } } } diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileAfterAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileAfterAttribute.cs index 71f9f7a3854b..a81898225225 100644 --- a/test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileAfterAttribute.cs +++ b/test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileAfterAttribute.cs @@ -13,8 +13,7 @@ public class SetupCompileAfterAttribute : BaseMetadataAttribute { public SetupCompileAfterAttribute (string outputName, string[] sourceFiles, string[] references = null, string[] defines = null, object[] resources = null, string additionalArguments = null, string compilerToUse = null, bool addAsReference = true, bool removeFromLinkerInput = false) { - if (sourceFiles == null) - throw new ArgumentNullException (nameof (sourceFiles)); + ArgumentNullException.ThrowIfNull (sourceFiles); if (string.IsNullOrEmpty (outputName)) throw new ArgumentException ("Value cannot be null or empty.", nameof (outputName)); diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileBeforeAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileBeforeAttribute.cs index 0021300c8403..73e5c69c20ca 100644 --- a/test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileBeforeAttribute.cs +++ b/test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileBeforeAttribute.cs @@ -13,8 +13,7 @@ public class SetupCompileBeforeAttribute : BaseMetadataAttribute { public SetupCompileBeforeAttribute (string outputName, string[] sourceFiles, string[] references = null, string[] defines = null, object[] resources = null, string additionalArguments = null, string compilerToUse = null, bool addAsReference = true, bool removeFromLinkerInput = false, string outputSubFolder = null) { - if (sourceFiles == null) - throw new ArgumentNullException (nameof (sourceFiles)); + ArgumentNullException.ThrowIfNull (sourceFiles); if (string.IsNullOrEmpty (outputName)) throw new ArgumentException ("Value cannot be null or empty.", nameof (outputName)); @@ -35,8 +34,7 @@ public SetupCompileBeforeAttribute (string outputName, string[] sourceFiles, str public SetupCompileBeforeAttribute (string outputName, Type[] typesToIncludeSourceFor, string[] references = null, string[] defines = null, object[] resources = null, string additionalArguments = null, string compilerToUse = null, bool addAsReference = true, bool removeFromLinkerInput = false) { - if (typesToIncludeSourceFor == null) - throw new ArgumentNullException (nameof (typesToIncludeSourceFor)); + ArgumentNullException.ThrowIfNull (typesToIncludeSourceFor); if (string.IsNullOrEmpty (outputName)) throw new ArgumentException ("Value cannot be null or empty.", nameof (outputName)); diff --git a/test/Mono.Linker.Tests/Extensions/NiceIO.cs b/test/Mono.Linker.Tests/Extensions/NiceIO.cs index ffc24695eb80..4fde1084de42 100644 --- a/test/Mono.Linker.Tests/Extensions/NiceIO.cs +++ b/test/Mono.Linker.Tests/Extensions/NiceIO.cs @@ -47,8 +47,7 @@ public class NPath : IEquatable, IComparable public NPath (string path) { - if (path == null) - throw new ArgumentNullException (nameof (path)); + ArgumentNullException.ThrowIfNull (path); path = ParseDriveLetter (path, out _driveLetter);