Repository: dotnet/runtime
File: src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ILVerification/ILChecker.cs (C#)

Code before:
        }
    }

    private static bool DisableILDiffing(TrimmedTestCaseResult linkResult, AssemblyDefinition original)
    {
        return linkResult.TestCase.FindTypeDefinition(original)
            .CustomAttributes
            .FirstOrDefault(attr => attr.AttributeType.Name == nameof(DisableILVerifyDiffingAttribute)) != null;
    }

    private static void ProcessExpectILFailures(TrimmedTestCaseResult linkResult, AssemblyDefinition original, out bool expectILFailures, out List<string> failureMessages)
    {
        var attrs = linkResult.TestCase.FindTypeDefinition(original).CustomAttributes.Where(attr => attr.AttributeType.Name == nameof(ExpectILFailureAttribute)).ToArray();
        expectILFailures = attrs.Length > 0;
        failureMessages = new List<string>();
        foreach (var attr in attrs)
        {
            var expectedMessageContains = ((CustomAttributeArgument[])attr.GetConstructorArgumentValue(0)).Select(a => (string)a.Value).ToArray();
            failureMessages.AddRange(expectedMessageContains);
        }
    }

    private void ProcessSkipAttributes(TrimmedTestCaseResult linkResult, AssemblyDefinition original, out bool skipCheckEntirely, out HashSet<string> assembliesToSkip)
    {
        var attrs = linkResult.TestCase.FindTypeDefinition(original).CustomAttributes.Where(attr => attr.AttributeType.Name == nameof(SkipILVerifyAttribute));
        skipCheckEntirely = false;
        assembliesToSkip = new HashSet<string>();
        foreach (var attr in attrs)
        {
            var ctorArg = attr.ConstructorArguments.FirstOrDefault();

            if (!attr.HasConstructorArguments)
            {
                skipCheckEntirely = true;
            }
            else if (ctorArg.Type.Name == nameof(String))
            {
                assembliesToSkip.Add((string)ctorArg.Value);
            }
            else
            {
                throw new ArgumentException($"Unhandled constructor argument type of {ctorArg.Type} on {nameof(SkipILVerifyAttribute)}");
            }
        }
    }

    public static ILVerifierResult[] Diff(ILVerifierResult[] outputResults, ILVerifierResult[] inputResults)
    {
        var inputErrors = new HashSet<ErrorKey>();

        foreach (var inputResult in inputResults)

Review comment (suggestion):
The intermediate list `errorsToIgnore` and foreach loop can be replaced with a single LINQ expression using `Select` and `ToArray()` for more concise code.
```suggestion
        var errorsToIgnore = attrs
            .Select(attr => (string)attr.GetConstructorArgumentValue(0))
            .ToArray();
```

Code after:
        else
        {
            if (hasFailures)
                Assert.Fail(failures);
        }
    }

    private static bool DisableILDiffing(TrimmedTestCaseResult linkResult, AssemblyDefinition original)
    {
        return linkResult.TestCase.FindTypeDefinition(original)
            .CustomAttributes
            .FirstOrDefault(attr => attr.AttributeType.Name == nameof(DisableILVerifyDiffingAttribute)) != null;
    }

    private static ILVerifierResult[] FilterIgnoredErrors(TrimmedTestCaseResult linkResult, AssemblyDefinition original, ILVerifierResult[] results)
    {
        var attrs = linkResult.TestCase.FindTypeDefinition(original).CustomAttributes.Where(attr => attr.AttributeType.Name == nameof(IgnoreILFailureAttribute)).ToArray();
        if (attrs.Length == 0)
            return results;

        var errorsToIgnore = new List<string>();
        foreach (var attr in attrs)
        {
            var expectedMessageContains = (string)attr.GetConstructorArgumentValue(0);
            errorsToIgnore.Add(expectedMessageContains);
        }

        var filtered = new List<ILVerifierResult>();
        foreach (var result in results)
        {
            if (!ShouldIgnore(result))
                filtered.Add(result);
        }

        return filtered.ToArray();

        bool ShouldIgnore(ILVerifierResult result)
        {
            foreach (var ignore in errorsToIgnore)
            {
                if (result.GetErrorMessage().Contains(ignore))
                    return true;
            }

            return false;
        }
    }

    private static void ProcessExpectILFailures(TrimmedTestCaseResult linkResult, AssemblyDefinition original, out bool expectILFailures, out List<string> failureMessages)
    {
        var attrs = linkResult.TestCase.FindTypeDefinition(original).CustomAttributes.Where(attr => attr.AttributeType.Name == nameof(ExpectILFailureAttribute)).ToArray();