5.2 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |||
|---|---|---|---|---|---|---|---|
|
2026-04-16T02:55:46.278352+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 9e68239f51c0c198 |
Validators
SensitivityValidator, UARTBAUDRateValidator, CANArbBaseBitrateValidator
1. Purpose
This module provides WPF ValidationRule implementations for validating user input in UI-bound numeric fields. Specifically, SensitivityValidator ensures sensitivity values are non-zero doubles, UARTBAUDRateValidator validates UART baud rates against embedded sensor constraints, and CANArbBaseBitrateValidator validates CAN arbitration/base bitrates using the widest applicable min/max range (to support both FD and non-FD CAN configurations). These validators are intended for use in XAML data binding scenarios to enforce input correctness before data propagation to the underlying model.
2. Public Interface
All classes inherit from System.Windows.Controls.ValidationRule and override the Validate method.
-
SensitivityValidator.Validate(object value, CultureInfo cultureInfo)
Validates thatvalueis a non-empty string parseable as adouble, and that the parsed value is non-zero. ReturnsValidationResult.IsValid = trueonly if both conditions hold; otherwise returnsfalsewith an appropriate localized error message (e.g.,"Invalid format"or"Sensitivity can not be zero"). -
UARTBAUDRateValidator.Validate(object value, CultureInfo cultureInfo)
Validates thatvalueis a string parseable as along, and that the parsed value lies within[EmbeddedSensors.BAUD_RATE_MIN, EmbeddedSensors.BAUD_RATE_MAX](inclusive). ReturnsValidationResult.IsValid = trueonly if both conditions hold; otherwise returnsfalsewith a message indicating the invalid value and the allowed range (e.g.,"Maximum value is 921600"). -
CANArbBaseBitrateValidator.Validate(object value, CultureInfo cultureInfo)
Validates thatvalueis a string parseable as along, and that the parsed value lies within[EmbeddedSensors.NON_CANFD_ARB_BASE_BITRATE_MIN, EmbeddedSensors.CANFD_ARB_BASE_BITRATE_MAX](inclusive). ReturnsValidationResult.IsValid = trueonly if both conditions hold; otherwise returnsfalsewith a message indicating the invalid value and the allowed range (e.g.,"Minimum value is 10000").
3. Invariants
- Input must be a
string; all non-string inputs (includingnull) are rejected with"Invalid format". - All numeric parsing uses
long.TryParse/double.TryParsewith defaultCultureInfo(invariant culture), meaning only standard decimal notation (e.g.,"123","-45.6") is accepted—no locale-specific separators (e.g., commas) are supported. SensitivityValidatorexplicitly rejects zero (0D) as invalid, even thoughdouble.TryParse("0", out var d)succeeds.UARTBAUDRateValidatorandCANArbBaseBitrateValidatorenforce inclusive bounds: values equal to*_MINor*_MAXare valid.- Error messages for range violations are constructed using
StringResources.MinValueIs/StringResources.MaxValueIsconcatenated with the respective constant value.
4. Dependencies
- Direct dependencies:
System.Windows.Controls.ValidationRule(base class)System.Globalization.CultureInfo(used inValidatesignature)DTS.Common.SharedResource.Strings.StringResources(for localized error strings)DTS.Common.Constant.EmbeddedSensors(forBAUD_RATE_MIN,BAUD_RATE_MAX,NON_CANFD_ARB_BASE_BITRATE_MIN,CANFD_ARB_BASE_BITRATE_MAX)
- Inferred consumers:
- XAML UI elements (e.g.,
TextBox) using these validators inValidationRulescollections. - Likely used in conjunction with
DTS.Common.SharedResource.Stringsresource files (e.g.,StringResources.InvalidFormat,StringResources.SensitivityCanNotBeZero, etc.).
- XAML UI elements (e.g.,
- No internal usage: These classes are not referenced internally in the provided source; they are standalone validators.
5. Gotchas
- Culture sensitivity: Parsing uses
CultureInfo.InvariantCultureimplicitly (viaTryParsewithout specifyingIFormatProvider), so inputs like"1,234"or"1.234,56"will fail even in cultures where they are valid. Users must enter plain decimal digits (e.g.,"1234.56"). - Range logic in
CANArbBaseBitrateValidator: The comment indicates the validator uses the widest possible range (min from non-FD, max from FD) to support both CAN types. This means valid values for one CAN type (e.g., FD-only min) may be rejected if outside the combined range. - Zero rejection in
SensitivityValidator: A value of"0"or"0.0"is rejected despite being a validdouble. This is likely intentional (sensitivity must be non-zero), but could be surprising if zero is a meaningful default elsewhere. - No support for scientific notation: Inputs like
"1e5"will faildouble.TryParse/long.TryParseand return"Invalid format". - Acronym naming:
UARTBAUDRateValidatorandCANArbBaseBitrateValidatorviolate PascalCase conventions (perS101suppression), but this is intentional for acronym clarity.