{"record":{"id":"d98fee5c6c98550d","repo":"AvaloniaUI/Avalonia","slug":"need-more-than-one-selector-to-or","errorCode":null,"errorMessage":"Need more than one selector to OR.","messagePattern":"Need more than one selector to OR\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Styling/OrSelector.cs","lineNumber":32,"sourceCode":"    {\n        private readonly IReadOnlyList<Selector> _selectors;\n        private string? _selectorString;\n        private Type? _targetType;\n\n        /// <summary>\n        /// Initializes a new instance of the <see cref=\"OrSelector\"/> class.\n        /// </summary>\n        /// <param name=\"selectors\">The selectors to OR.</param>\n        public OrSelector(IReadOnlyList<Selector> selectors)\n        {\n            if (selectors is null)\n            {\n                throw new ArgumentNullException(nameof(selectors));\n            }\n\n            if (selectors.Count <= 1)\n            {\n                throw new ArgumentException(\"Need more than one selector to OR.\");\n            }\n\n            _selectors = selectors;\n        }\n\n        /// <inheritdoc/>\n        internal override bool InTemplate => false;\n\n        /// <inheritdoc/>\n        internal override bool IsCombinator => false;\n\n        /// <inheritdoc/>\n        internal override Type? TargetType => _targetType ??= EvaluateTargetType();\n\n        /// <inheritdoc/>\n        public override string ToString(Style? owner) => ToString(owner, false);\n\n        /// <inheritdoc/>","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Styling/OrSelector.cs#L14-L50","documentation":"Thrown by the OrSelector constructor when the supplied selector list has zero or one elements. The `Selectors.Or(...)` helper requires at least two selectors; OR-ing a single or empty set is meaningless and treated as an error. Selectors are stored right-to-left, so the OR group needs multiple branches.","triggerScenarios":"Calling `Selectors.Or(singleSelector)` or `Selectors.Or()` with fewer than two arguments; passing a filtered/empty `IReadOnlyList<Selector>` to the `Or(IReadOnlyList<Selector>)` overload.","commonSituations":"Dynamically building an OR selector list that filtering reduced to one element; mistakenly wrapping a single selector in Or(); copy-paste leaving only one branch.","solutions":["Pass at least two selectors to Selectors.Or().","If building dynamically, use the single selector directly when only one remains, and handle the empty case separately.","Validate the array/list length before calling Or()."],"exampleFix":"// before\nvar s = Selectors.Or(items.Select(BuildSelector).ToArray()); // may be <=1\n\n// after\nvar built = items.Select(BuildSelector).ToArray();\nSelector result = built.Length switch\n{\n    0 => throw new InvalidOperationException(\"no selectors\"),\n    1 => built[0],\n    _ => Selectors.Or(built)\n};","handlingStrategy":"validation","validationCode":"if (selectors is null || selectors.Length < 2)\n    throw new ArgumentException(\"Or requires at least two selectors.\", nameof(selectors));\nvar sel = Selectors.Or(selectors);","typeGuard":"static bool CanOr(IReadOnlyList<Selector> s) => s is { Count: >= 2 };","tryCatchPattern":null,"preventionTips":["Guard dynamic selector lists: use the single element directly when length is 1.","Validate length before calling Selectors.Or().","Write a small builder helper that enforces the minimum count."],"tags":["avalonia","styling","or-selector","validation"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}