{"record":{"id":"c6c9cb4577b58d1c","repo":"babalae/better-genshin-impact","slug":"itemname-itemnames-c6c9cb","errorCode":null,"errorMessage":"参数ItemName和ItemNames不能同时为空","messagePattern":"参数ItemName和ItemNames不能同时为空","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/GameTask/Common/Job/CountInventoryItemParam.cs","lineNumber":50,"sourceCode":"\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":32,"sourceCodeEnd":59,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/GameTask/Common/Job/CountInventoryItemParam.cs#L32-L59","documentation":"Thrown as ArgumentException by CountInventoryItemParam.Validate when both ItemName and ItemNames are empty/whitespace. The task needs at least one item name to count; providing none means there is nothing to do and indicates a caller error.","triggerScenarios":"Constructing a CountInventoryItemParam without setting ItemName or ItemNames (both left at defaults: null and empty list), then calling Validate().","commonSituations":"A script creates the param object but forgets to populate the item name(s). The item name was read from user input that turned out to be empty. A deserialized config object had both fields blank.","solutions":["Set at least one of ItemName or ItemNames before calling Validate().","Add an earlier guard in the calling code to reject empty user input before constructing the param.","If counting is optional, skip the task entirely rather than validating an empty param."],"exampleFix":"// before\nvar param = new CountInventoryItemParam { GridScreenName = ... };\nparam.Validate(); // throws — no item specified\n\n// after\nvar param = new CountInventoryItemParam { GridScreenName = ..., ItemName = \"摩拉\" };\nparam.Validate();","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(param.ItemName) && param.ItemNames.Count == 0)\n{\n    // no items specified — abort or prompt user\n}","typeGuard":"static bool HasAtLeastOneItem(CountInventoryItemParam p)\n    => !string.IsNullOrWhiteSpace(p.ItemName) || p.ItemNames.Count > 0;","tryCatchPattern":"try { param.Validate(); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"不能同时为空\")) { /* prompt for item name */ }","preventionTips":["Require item specification in the UI/config layer before building the param.","Use a constructor that mandates at least one item name."],"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"}