{"record":{"id":"991e6d3b8a9a3c62","repo":"babalae/better-genshin-impact","slug":"itemname-itemnames","errorCode":null,"errorMessage":"参数ItemName和ItemNames不能同时使用","messagePattern":"参数ItemName和ItemNames不能同时使用","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/GameTask/Common/Job/CountInventoryItemParam.cs","lineNumber":45,"sourceCode":"\n    public IEnumerable<string>? GetItemNamesOrNull()\n    {\n        return ItemNames.Count > 0 ? ItemNames : null;\n    }\n\n    public void Validate()\n    {\n        ItemNames ??= [];\n        bool hasItemName = !string.IsNullOrWhiteSpace(ItemName);\n        bool hasItemNames = ItemNames.Count > 0;\n        if (!hasItemName)\n        {\n            ItemName = null;\n        }\n\n        if (hasItemName && hasItemNames)\n        {\n            throw new ArgumentException($\"参数{nameof(ItemName)}和{nameof(ItemNames)}不能同时使用\");\n        }\n\n        if (!hasItemName && !hasItemNames)\n        {\n            throw new ArgumentException($\"参数{nameof(ItemName)}和{nameof(ItemNames)}不能同时为空\");\n        }\n\n        if (ItemNames.Any(string.IsNullOrWhiteSpace))\n        {\n            throw new ArgumentException($\"参数{nameof(ItemNames)}不能包含空名称\");\n        }\n    }\n}\n","sourceCodeStart":27,"sourceCodeEnd":59,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/GameTask/Common/Job/CountInventoryItemParam.cs#L27-L59","documentation":"Thrown as ArgumentException by CountInventoryItemParam.Validate when both ItemName (single) and ItemNames (list) are non-empty simultaneously. The task accepts exactly one form of item specification to avoid ambiguity in which items to count; providing both is treated as a caller bug.","triggerScenarios":"Constructing a CountInventoryItemParam and setting both ItemName = \"someItem\" and ItemNames = [\"item1\", \"item2\"], then calling Validate().","commonSituations":"A script or UI builder populates both fields from different code paths and forgets to clear one. Copy-paste from another param object leaves a stale ItemName alongside a new ItemNames list.","solutions":["Set only ItemName for a single item, or only ItemNames for multiple — never both.","Before calling Validate(), explicitly null out the field you are not using.","Review the code that constructs CountInventoryItemParam to ensure it picks one branch."],"exampleFix":"// before\nparam.ItemName = \"树脂\";\nparam.ItemNames = new List<string> { \"树脂\", \"原石\" };\nparam.Validate(); // throws\n\n// after\nparam.ItemName = null;\nparam.ItemNames = new List<string> { \"树脂\", \"原石\" };\nparam.Validate();","handlingStrategy":"validation","validationCode":"if (!string.IsNullOrWhiteSpace(param.ItemName) && param.ItemNames.Count > 0)\n{\n    // pick one: clear ItemNames if using single name\n    param.ItemNames.Clear();\n}","typeGuard":"static bool IsParamExclusive(CountInventoryItemParam p)\n{\n    bool hasName = !string.IsNullOrWhiteSpace(p.ItemName);\n    bool hasList = p.ItemNames.Count > 0;\n    return hasName ^ hasList;\n}","tryCatchPattern":"try { param.Validate(); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"不能同时使用\")) { /* clear one field, retry */ }","preventionTips":["Use a factory method that enforces exclusivity instead of setting both fields.","Review all construction sites for CountInventoryItemParam."],"tags":["validation","inventory","argument-error"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}