internal bool Evaluate()

in src/Microsoft.TestPlatform.Common/Filtering/Condition.cs [98:174]


    internal bool Evaluate(Func<string, object> propertyValueProvider)
    {
        ValidateArg.NotNull(propertyValueProvider, nameof(propertyValueProvider));
        var result = false;
        var multiValue = GetPropertyValue(propertyValueProvider);
        switch (Operation)
        {
            case Operation.Equal:
                // if any value in multi-valued property matches 'this.Value', for Equal to evaluate true.
                if (null != multiValue)
                {
                    foreach (string propertyValue in multiValue)
                    {
                        result = result || string.Equals(propertyValue, Value, StringComparison.OrdinalIgnoreCase);
                        if (result)
                        {
                            break;
                        }
                    }
                }
                break;


            case Operation.NotEqual:
                // all values in multi-valued property should not match 'this.Value' for NotEqual to evaluate true.
                result = true;

                // if value is null.
                if (null != multiValue)
                {
                    foreach (string propertyValue in multiValue)
                    {
                        result = result && !string.Equals(propertyValue, Value, StringComparison.OrdinalIgnoreCase);
                        if (!result)
                        {
                            break;
                        }
                    }
                }
                break;

            case Operation.Contains:
                // if any value in multi-valued property contains 'this.Value' for 'Contains' to be true.
                if (null != multiValue)
                {
                    foreach (string propertyValue in multiValue)
                    {
                        Debug.Assert(null != propertyValue, "PropertyValue can not be null.");
                        result = result || propertyValue.IndexOf(Value, StringComparison.OrdinalIgnoreCase) != -1;
                        if (result)
                        {
                            break;
                        }
                    }
                }
                break;

            case Operation.NotContains:
                // all values in multi-valued property should not contain 'this.Value' for NotContains to evaluate true.
                result = true;

                if (null != multiValue)
                {
                    foreach (string propertyValue in multiValue)
                    {
                        Debug.Assert(null != propertyValue, "PropertyValue can not be null.");
                        result = result && propertyValue.IndexOf(Value, StringComparison.OrdinalIgnoreCase) == -1;
                        if (!result)
                        {
                            break;
                        }
                    }
                }
                break;
        }
        return result;
    }