Repository: AvaloniaUI/Avalonia
File: src/Avalonia.Base/Styling/ChildSelector.cs (C#)

Code before:

        public ChildSelector(Selector parent)
        {
            if (parent == null)
            {
                throw new InvalidOperationException("Child selector must be preceeded by a selector.");
            }

            _parent = parent;
        }

        /// <inheritdoc/>
        internal override bool InTemplate => _parent.InTemplate;

        /// <inheritdoc/>
        internal override bool IsCombinator => true;

        /// <inheritdoc/>
        internal override Type? TargetType => null;

        public override string ToString(Style? owner)
        {
            if (_selectorString == null)
            {
                _selectorString = _parent is OrSelector ?
                    $"({_parent.ToString(owner)}) > " :
                    _parent.ToString(owner) + " > ";
            }

            return _selectorString;
        }

        private protected override SelectorMatch Evaluate(StyledElement control, IStyle? parent, bool subscribe)
        {
            var controlParent = ((ILogical)control).LogicalParent;

            if (controlParent != null)
            {
                var parentMatch = _parent.Match((StyledElement)controlParent, parent, subscribe);

                if (parentMatch.Result == SelectorMatchResult.Sometimes)
                {
                    return parentMatch;
                }
                else if (parentMatch.IsMatch)
                {
                    return SelectorMatch.AlwaysThisInstance;
                }
                else
                {
                    return SelectorMatch.NeverThisInstance;

Review comment (suggestion):
Note: all selectors have been modified to add parenthesis around `OrSelector`, why not add this directly to `OrSelector.ToString()`? You could add an internal override taking a flag to avoid adding parenthesis around an `OrSelector` being placed at the root level.

Code after:

        public ChildSelector(Selector parent)
        {
            if (parent == null)
            {
                throw new InvalidOperationException("Child selector must be preceeded by a selector.");
            }

            _parent = parent;
        }

        /// <inheritdoc/>
        internal override bool InTemplate => _parent.InTemplate;

        /// <inheritdoc/>
        internal override bool IsCombinator => true;

        /// <inheritdoc/>
        internal override Type? TargetType => null;

        public override string ToString(Style? owner)
        {
            if (_selectorString == null)
            {
                _selectorString = _parent.ToString(owner, true) + " > ";
            }

            return _selectorString;
        }

        private protected override SelectorMatch Evaluate(StyledElement control, IStyle? parent, bool subscribe)
        {
            var controlParent = ((ILogical)control).LogicalParent;

            if (controlParent != null)
            {
                var parentMatch = _parent.Match((StyledElement)controlParent, parent, subscribe);

                if (parentMatch.Result == SelectorMatchResult.Sometimes)
                {
                    return parentMatch;
                }
                else if (parentMatch.IsMatch)
                {
                    return SelectorMatch.AlwaysThisInstance;
                }
                else
                {
                    return SelectorMatch.NeverThisInstance;
                }
            }