105 lines
5.9 KiB
Markdown
105 lines
5.9 KiB
Markdown
|
|
---
|
|||
|
|
source_files:
|
|||
|
|
- DataPRO/Modules/Hardware/HardwareList/Converters/FirstUseDateConverter.cs
|
|||
|
|
- DataPRO/Modules/Hardware/HardwareList/Converters/StandInFieldConverter.cs
|
|||
|
|
generated_at: "2026-04-16T04:37:34.782938+00:00"
|
|||
|
|
model: "Qwen/Qwen3-Coder-Next-FP8"
|
|||
|
|
schema_version: 1
|
|||
|
|
sha256: "aee017cd34357419"
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
# Converters
|
|||
|
|
|
|||
|
|
## Documentation: `HardwareList.Converters` Module
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
### 1. **Purpose**
|
|||
|
|
|
|||
|
|
This module provides WPF value converters for formatting and conditional display of hardware-related properties in UI-bound data grids or forms. Specifically, `FirstUseDateConverter` and `StandInFieldConverter` translate raw model data into user-friendly string representations (e.g., `"N/A"`, `"---"`, or actual `DateTime` values), handling edge cases such as missing, invalid, or inapplicable data based on hardware state (e.g., `StandIn` flag). These converters enable consistent, declarative UI formatting without cluttering view models with presentation logic.
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
### 2. **Public Interface**
|
|||
|
|
|
|||
|
|
#### `FirstUseDateConverter`
|
|||
|
|
*Namespace:* `HardwareList.Converters`
|
|||
|
|
*Implements:* `IValueConverter`
|
|||
|
|
|
|||
|
|
- **`Convert(object value, Type targetType, object parameter, CultureInfo culture)`**
|
|||
|
|
- **Behavior:**
|
|||
|
|
- If `value` is not a `HardareList.Model.HardwareModel`, returns `Strings.Table_NA`.
|
|||
|
|
- If `model.IsFirstUseValid` is `false`, returns `Strings.NotApplicable`.
|
|||
|
|
- If `model.FirstUseDate` is non-null, returns `model.FirstUseDate` (as `DateTime?`).
|
|||
|
|
- Otherwise, returns `Strings.Table_NA`.
|
|||
|
|
- **Return type:** `object` (typically `string` or `DateTime?`).
|
|||
|
|
|
|||
|
|
- **`ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)`**
|
|||
|
|
- **Behavior:**
|
|||
|
|
- If `value` is a `DateTime`, returns it.
|
|||
|
|
- Otherwise, returns `Strings.Table_NA`.
|
|||
|
|
- **Note:** This is a minimal reverse converter; it does not validate or parse strings.
|
|||
|
|
- **Return type:** `object`.
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
#### `StandInFieldConverter`
|
|||
|
|
*Namespace:* `HardwareList.Converters`
|
|||
|
|
*Implements:* `IValueConverter`
|
|||
|
|
|
|||
|
|
- **`Convert(object value, Type targetType, object parameter, CultureInfo culture)`**
|
|||
|
|
- **Behavior:**
|
|||
|
|
- If `value` is not a `HardareList.Model.HardwareModel`, returns `Strings.Table_NA`.
|
|||
|
|
- If `model.Hardware` does not implement `IISOHardware`, returns `string.Empty`.
|
|||
|
|
- If `isoHW.StandIn` is `true`, returns `Strings.Table_NA`.
|
|||
|
|
- If `parameter` is a `string` matching `"CalDueDate"`, `"CalDate"`, or `"Firmware"`, returns the corresponding property (`model.CalDueDate`, `model.CalDate`, or `model.Firmware`).
|
|||
|
|
- Otherwise, returns `Strings.Table_NA`.
|
|||
|
|
- **Return type:** `object` (typically `string`, `DateTime?`, or `object` depending on the requested field).
|
|||
|
|
|
|||
|
|
- **`ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)`**
|
|||
|
|
- **Behavior:**
|
|||
|
|
- If `value` is a `DateTime`, returns it.
|
|||
|
|
- Otherwise, returns `Strings.Table_NA`.
|
|||
|
|
- **Return type:** `object`.
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
### 3. **Invariants**
|
|||
|
|
|
|||
|
|
- **Type Safety:** Both converters expect the input `value` to be a `HardareList.Model.HardwareModel`. Failure to meet this results in fallback to `Strings.Table_NA`.
|
|||
|
|
- **Null Handling:**
|
|||
|
|
- `FirstUseDateConverter` treats `null` `FirstUseDate` as `"---"` (`Strings.Table_NA`), distinct from `IsFirstUseValid == false` which yields `"N/A"` (`Strings.NotApplicable`).
|
|||
|
|
- `StandInFieldConverter` short-circuits to `Strings.Table_NA` if `isoHW.StandIn` is `true`, regardless of the requested field.
|
|||
|
|
- **Parameter Dependency (StandInFieldConverter only):**
|
|||
|
|
- The converter’s output depends critically on the `parameter` being a `string` matching one of the three known keys (`"CalDueDate"`, `"CalDate"`, `"Firmware"`). Any other parameter yields `Strings.Table_NA`.
|
|||
|
|
- **No Validation on ConvertBack:** Both converters perform no validation or parsing in `ConvertBack`; they only pass through `DateTime` values or return `Strings.Table_NA`.
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
### 4. **Dependencies**
|
|||
|
|
|
|||
|
|
- **Internal Dependencies (from source):**
|
|||
|
|
- `HardareList.Model.HardwareModel` (note: likely typo in namespace `HardareList` vs. `HardwareList`).
|
|||
|
|
- `DTS.Common.Strings` (provides `Strings.Table_NA`, `Strings.NotApplicable`).
|
|||
|
|
- `DTS.Common.Interface.DASFactory.Diagnostics.IISOHardware` (used in `StandInFieldConverter`).
|
|||
|
|
- `System.Windows.Data.IValueConverter` (WPF base interface).
|
|||
|
|
|
|||
|
|
- **External Dependencies:**
|
|||
|
|
- WPF framework (for `IValueConverter` usage in XAML).
|
|||
|
|
- `DTS.Common` assembly (contains `Strings` and `IISOHardware`).
|
|||
|
|
|
|||
|
|
- **Depended Upon By:**
|
|||
|
|
- UI layers (XAML bindings) referencing these converters in `DataGrid` columns or `TextBlock` bindings for hardware properties.
|
|||
|
|
- No direct code dependencies inferred—converters are consumed via XAML markup extension or resource references.
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
### 5. **Gotchas**
|
|||
|
|
|
|||
|
|
- **Typo in Namespace:** The model type is referenced as `HardareList.Model.HardwareModel` (missing 'w' in "Hardware"), which may cause runtime binding failures if the actual namespace is `HardwareList`.
|
|||
|
|
- **Ambiguous `parameter` Usage:** `StandInFieldConverter` relies on string literals for field selection (`"CalDueDate"`, etc.). Typos or case mismatches in XAML parameter values will silently fall back to `Strings.Table_NA`.
|
|||
|
|
- **Inconsistent `ConvertBack` Behavior:** Both converters return `Strings.Table_NA` for non-`DateTime` inputs in `ConvertBack`, which may be misleading if the UI expects a `null` or `DateTime?` result (e.g., for nullable fields like `CalDueDate`).
|
|||
|
|
- **No Handling for Invalid `IISOHardware` Cast:** In `StandInFieldConverter`, if `model.Hardware` is non-null but not `IISOHardware`, the converter returns `string.Empty`—a subtle distinction from `Strings.Table_NA` (`"---"`), which could cause visual inconsistency.
|
|||
|
|
- **Missing Documentation for `Strings` Values:** While `Strings.Table_NA` and `Strings.NotApplicable` are used, their exact string values (e.g., `"---"` vs `"N/A"`) are not visible in this source and must be verified in `DTS.Common.Strings`.
|
|||
|
|
|
|||
|
|
*None identified beyond the above.*
|