4.4 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |
|---|---|---|---|---|---|
|
2026-04-16T11:54:41.555458+00:00 | zai-org/GLM-5-FP8 | 1 | 96c94c51da2a1b2d |
Documentation: CustomChannelFieldSizeAttribute.cs
1. Purpose
This module provides a mechanism for associating fixed size metadata with enum values (specifically MMETables.MMEPossibleChannelsFields), enabling retrieval of custom field sizes via reflection. It exists to decouple size configuration from business logic, allowing channel field sizes to be defined declaratively as attributes on enum members rather than hard-coded elsewhere.
2. Public Interface
CustomChannelFieldSizeAttribute (Class)
A custom attribute that stores an integer size value.
| Member | Signature | Description |
|---|---|---|
| Constructor | internal CustomChannelFieldSizeAttribute(int size) |
Creates an instance with the specified size. Note: Internal access only. |
| Property | public int Size { get; private set; } |
Gets the size value. Read-only after construction. |
CustomChannelFieldSizeExtensions (Static Class)
Provides helper methods for retrieving field sizes.
| Method | Signature | Description |
|---|---|---|
GetFieldSize |
public static int GetFieldSize(MMETables.MMEPossibleChannelsFields field) |
Retrieves the Size value from the CustomChannelFieldSizeAttribute applied to the given enum value. Not an extension method—must be called statically. |
EnumExtensions (Static Class)
Provides generic reflection-based attribute retrieval for enum values.
| Method | Signature | Description |
|---|---|---|
GetAttribute<TAttribute> |
public static TAttribute GetAttribute<TAttribute>(this Enum value) where TAttribute : Attribute |
Extension method that retrieves a single custom attribute of type TAttribute from the given enum value. Returns null if not found; throws InvalidOperationException if multiple matching attributes exist. |
3. Invariants
- Attribute Application:
GetFieldSizeassumes thatCustomChannelFieldSizeAttributeis always applied to the passedMMEPossibleChannelsFieldsenum value. If the attribute is missing, aNullReferenceExceptionwill occur. - Single Attribute Constraint:
GetAttribute<TAttribute>usesSingleOrDefault(), enforcing that at most one attribute of a given type may be present on any enum value. Multiple attributes of the same type will cause anInvalidOperationException. - Immutability: The
Sizeproperty is set only at construction and cannot be modified thereafter (private setter). - Construction Restriction: The attribute constructor is
internal, meaning attributes can only be defined within the same assembly.
4. Dependencies
This module depends on:
System(forAttribute,Enum,Typereflection APIs)System.Linq(forOfType<T>(),SingleOrDefault())MMETables.MMEPossibleChannelsFields— an external enum type that this module is designed to annotate. Location/assembly not visible in source.
What depends on this module:
- Cannot be determined from source alone. Consumers would be any code that needs to retrieve field sizes for
MMEPossibleChannelsFieldsenum values.
5. Gotchas
-
GetFieldSizeis NOT an extension method — Despite being defined in a class namedCustomChannelFieldSizeExtensions, the method lacks thethiskeyword on its parameter. It must be called asCustomChannelFieldSizeExtensions.GetFieldSize(field), notfield.GetFieldSize(). -
Potential
NullReferenceException—GetFieldSizedirectly accesses.Sizeon the result ofGetAttribute<CustomChannelFieldSizeAttribute>()without null-checking. If the enum value lacks this attribute, the method will throw. -
Internal constructor limits extensibility — The
internalconstructor means consumers outside this assembly cannot create new instances ofCustomChannelFieldSizeAttribute. This is likely intentional to control where/how the attribute is applied, but could be restrictive for testing or extension scenarios. -
Tight coupling to specific enum type —
GetFieldSizeis hardcoded toMMETables.MMEPossibleChannelsFields, making this utility non-reusable for other enums even thoughGetAttribute<T>is generic.