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

Code before:
    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)
        {
            inputErrors.Add(CreateKey(inputResult));
        }

        var newErrors = new List<ILVerifierResult>();

        foreach (var outputResult in outputResults)
        {
            var key = CreateKey(outputResult);


Review comment (suggestion):
This filtering logic can be simplified using LINQ's `Where` method: `return results.Where(r => !ShouldIgnore(r)).ToArray();` which would make the code more concise and eliminate the need for the intermediate list.
```suggestion
        return results.Where(result => !ShouldIgnore(result)).ToArray();
```

Code after:
            .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();
        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)