{"record":{"id":"33eb8ce1385a848e","repo":"tui-cs/Terminal.Gui","slug":"t-must-be-a-numeric-type-that-supports-addition-an","errorCode":null,"errorMessage":"T must be a numeric type that supports addition and subtraction.","messagePattern":"T must be a numeric type that supports addition and subtraction\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/Views/NumericUpDown.cs","lineNumber":66,"sourceCode":"    private readonly ScrollButton _up;\n\n    private View _number;\n    private TextField? _editor;\n    private bool _updatingText;\n    private bool _editingFromUser;\n    private bool _canEdit;\n\n    /// <summary>\n    ///     Initializes a new instance of the <see cref=\"NumericUpDown{T}\"/> class.\n    /// </summary>\n    /// <exception cref=\"InvalidOperationException\"></exception>\n    public NumericUpDown ()\n    {\n        Type type = typeof (T);\n\n        if (!(type == typeof (object) || NumericHelper.SupportsType (type)))\n        {\n            throw new InvalidOperationException (\"T must be a numeric type that supports addition and subtraction.\");\n        }\n\n        CanFocus = true;\n\n        Width = Dim.Auto (DimAutoStyle.Content);\n        Height = Dim.Auto (DimAutoStyle.Content);\n\n        _down = new ScrollButton\n        {\n            Orientation = Orientation.Vertical,\n            Direction = NavigationDirection.Forward\n        };\n\n        _number = CreateNumberView ();\n\n        _up = new ScrollButton\n        {\n            X = Pos.Right (_number),","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Views/NumericUpDown.cs#L48-L84","documentation":"Thrown by the NumericUpDown<T> constructor when T is not 'object' and NumericHelper.SupportsType(type) returns false — i.e. T is a type without addition/subtraction operators that the helper recognises. NumericUpDown needs to add/subtract the increment, so unsupported generic type arguments are rejected at construction rather than failing later on every keystroke.","triggerScenarios":"Constructing NumericUpDown<SomeEnum>, NumericUpDown<string>, NumericUpDown<CustomStruct> (no matching operators), or NumericUpDown<Guid>. Supported types are the numeric primitives handled by NumericHelper.","commonSituations":"Trying to use NumericUpDown for an enum (use OptionSelector/FlagSelector instead); wrapping a domain value type that lacks operator overloads; copy-pasting NumericUpDown<double> into a custom value-object generic.","solutions":["Use a supported numeric type: int, long, decimal, double, float, etc. — check NumericHelper.SupportsType for the exact list.","For enums use OptionSelectorTEnum; for flags use FlagSelectorTEnum.","If a custom numeric struct is required, ensure it exposes matching +/- operators and register/support it via the helper's accepted set, or wrap a supported primitive."],"exampleFix":"// before\nvar nud = new NumericUpDown<MyEnum>(); // throws 168\n\n// after\nvar nud = new NumericUpDown<int>();\n// and for enums prefer:\nvar sel = new OptionSelectorTEnum<MyEnum>();","handlingStrategy":"type-guard","validationCode":"Type t = typeof(T);\nif (!(t == typeof(object) || NumericHelper.SupportsType(t)))\n{\n    // pick a supported numeric type, or use OptionSelector for enums\n}","typeGuard":"static bool SupportsNumericUpDown<T>() =>\n    typeof(T) == typeof(object) || NumericHelper.SupportsType(typeof(T));","tryCatchPattern":null,"preventionTips":["Use int/long/decimal/double/float for NumericUpDown<T>.","Use OptionSelectorTEnum for enums, FlagSelectorTEnum for flags.","Check NumericHelper.SupportsType before binding a generic type argument."],"tags":["numericupdown","generics","validation","precondition"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}