9.0 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | ||||
|---|---|---|---|---|---|---|---|---|
|
2026-04-16T04:58:12.148784+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 290a5af10b3d9412 |
Documentation: DatabaseExport.Utilities Module
1. Purpose
This module provides foundational utilities for the DatabaseExport subsystem, specifically supporting attribute-based encoding/decoding of enum values and basic file/path name validation. It enables a consistent pattern for associating metadata (attributes) with enum members and mapping between those metadata values and the enums themselves. The module also establishes a base class hierarchy (Exceptional, ExceptionalList<T>) for type-specific exception handling, allowing callers to catch exceptions by their originating class type. This module is part of a legacy codebase targeting database version 57 export functionality.
2. Public Interface
DiskUtility
A static utility class for validating file and path names.
ValidateFileAndPathNameChars(string nameToValidate)- Signature:
public static bool ValidateFileAndPathNameChars(string nameToValidate) - Behavior: Returns
trueifnameToValidatecontains no characters fromPath.GetInvalidFileNameChars()orPath.GetInvalidPathChars(), has non-zero length after trimming, and does not contain a period (.). Returnsfalseotherwise. - Note: Explicitly rejects any string containing
.(e.g., file extensions), beyond standard OS-invalid characters.
- Signature:
Exceptional
An abstract base class for enabling type-specific exception handling.
- No public methods or properties.
- Purpose: Serves as a marker base class. Derived classes may define nested
Exceptiontypes (as shown in the remarks), but the base class itself provides no runtime behavior beyond being serializable.
ExceptionalList<T>
A generic list class inheriting from List<T> for type-specific exception handling.
- No public methods or properties beyond those inherited from
List<T>. - Purpose: Provides a base type that can be subclassed to define custom exception types (e.g.,
MyList : ExceptionalList<int> { public class Exception : System.Exception { ... } }), per the pattern described in the remarks.
AttributeCoder<TargetType, AttributeType, AttributeValueType>
A generic helper for mapping between enum values (TargetType), their associated attributes (AttributeType), and extracted values (AttributeValueType).
-
Delegates:
AttributeValueExtractionMethod(AttributeType attribute) → AttributeValueType
Defines how to extract anAttributeValueTypefrom anAttributeTypeinstance.AttributeValueEqualityComparisonMethod(AttributeValueType, AttributeValueType) → bool
Defines custom equality logic forAttributeValueType. Ifnull, defaults toEquals().
-
Constructors:
AttributeCoder(AttributeValueExtractionMethod, AttributeValueEqualityComparisonMethod = null)
Initializes the coder. ThrowsExceptionifattributeValueExtractionMethodisnull. Stores both delegates.
-
Methods:
DecodeAttributeValue(TargetType target) → AttributeValueType
Extracts the singleAttributeValueTypefrom the attribute attached totarget.- Internally calls
DecodeAttributeValues(target)and asserts exactly one value exists. - Throws
Exceptionif no attributes found or if multiple attributes exist.
- Internally calls
DecodeAttributeValues(TargetType target) → List<AttributeValueType>
Extracts allAttributeValueTypes from attributes of typeAttributeTypeattached totarget.- Uses reflection:
target.GetType().GetField(target.ToString())to get theFieldInfoof the enum field named bytarget.ToString(). - Retrieves custom attributes of type
AttributeTypeon that field. - Applies
_extractAttributeValueto each attribute to produce the list.
- Uses reflection:
EncodeAttributeValue(AttributeValueType attributeValue) → TargetType
Returns the singleTargetTypeenum value whose attribute hasattributeValue.- Internally calls
DehashAttributeValue(attributeValue)and asserts exactly one match. - Throws
Exceptionif zero or multiple matches.
- Internally calls
DehashAttributeValue(AttributeValueType attributeValue) → List<TargetType>
Returns allTargetTypeenum values whose attributes matchattributeValue.- Enumerates all values of
TargetTypeviaEnum.GetValues(typeof(TargetType)). - For each, calls
DecodeAttributeValue(target)and compares toattributeValueusing either_areAttributeValuesEqual(if provided) orEquals(). - Throws
Exceptionif no matches found.
- Enumerates all values of
3. Invariants
-
DiskUtility.ValidateFileAndPathNameChars:- A valid name must be non-empty after trimming, contain no invalid filename/path characters (per
Path.GetInvalidFileNameChars()/Path.GetInvalidPathChars()), and contain no.characters. - Critical constraint: The presence of
.alone causes rejection, regardless of other validity.
- A valid name must be non-empty after trimming, contain no invalid filename/path characters (per
-
AttributeCoder:DecodeAttributeValueandEncodeAttributeValueassume exactly one attribute per enum field and exactly one enum field per attribute value, respectively. They throw if this is violated.DecodeAttributeValuesandDehashAttributeValuedo not assume uniqueness and return lists.DecodeAttributeValuesrelies on theTargetTypebeing anenumand thattarget.ToString()yields a valid field name on the enum type.- The
AttributeTypemust be applied as a custom attribute on the enum field (not the value itself), andGetField(target.ToString())must succeed. AttributeValueExtractionMethodmust be non-null;AttributeValueEqualityComparisonMethodmay benull(defaults toEquals).
4. Dependencies
This module depends on:
System.IO(forPath.GetInvalidFileNameChars(),Path.GetInvalidPathChars())System.Linq(forCast<T>(),Where(),Select(),ToList())System.Diagnostics(forDebug.Assert)System.Collections.Generic(forList<T>)System(forException,SerializableAttribute,Enum)
This module is depended upon by:
- Inferred: Other modules in
DatabaseExport(not visible here) likely useAttributeCoderto map between enums and metadata (e.g., database column types, export options). DiskUtilityis likely used by export logic that constructs file paths dynamically.Exceptional/ExceptionalList<T>are base types; specific subclasses (not provided) are used throughout the codebase for typed exceptions.
5. Gotchas
-
DiskUtility.ValidateFileAndPathNameChars:- The explicit ban on
.is non-standard and may conflict with typical file naming conventions (e.g.,.txt,data.csv). This is likely intentional to prevent extension confusion in internal naming, but is a critical constraint. - Validation is case-sensitive for content (e.g.,
..is invalid, but..is not explicitly checked beyond.presence).
- The explicit ban on
-
AttributeCoder:- Fragile reflection usage:
target.GetType().GetField(target.ToString())assumes theTargetTypeis anenumand thatToString()returns the exact field name. IfTargetTypeis not an enum, or if customToString()overrides exist, this will fail. - No support for multiple attributes per field:
DecodeAttributeValuescollects all attributes ofAttributeType, butDecodeAttributeValueexpects exactly one and throws otherwise. - Equality semantics: If
_areAttributeValuesEqualisnull,Equals()is used. Value types (e.g.,int,string) usually work, but reference types may require custom equality (e.g., for case-insensitive strings). - Exception messages are not localized: Commented-out
Resources.*strings indicate localization was intended but not implemented. All exceptions use hardcoded English strings. - No null-safety on
target: PassingnulltoDecodeAttributeValue/DecodeAttributeValueswill throwNullReferenceExceptionbefore reaching intended error handling. EncodeAttributeValue/DehashAttributeValueare inverses only if the mapping is bijective: If multiple enum values map to the same attribute value,EncodeAttributeValuewill fail.
- Fragile reflection usage:
-
Exceptional/ExceptionalList<T>:- These classes provide no runtime behavior beyond inheritance. Their utility relies on subclasses defining nested
Exceptiontypes (as shown in remarks), which are not present in the provided source. Callers must infer usage from comments. ExceptionalList<T>adds no functionality beyondList<T>; it is only a marker for exception hierarchy.
- These classes provide no runtime behavior beyond inheritance. Their utility relies on subclasses defining nested