Aliases
Zongsoft.Components AliasAttribute alias declaration and reading.
AliasAttribute is used to declare one or more aliases for an assembly, module, type, member, or parameter. It is commonly used to map external inputs, configuration names, command names, or plugin names to internal members.
The design focus of aliases is "stable matching", not display text. A component can have multiple historical names, abbreviations, or external configuration names and still be processed through the same type or member at runtime.
Key Capabilities
Multiple declarations
AllowMultiple = true, the same target can have multiple aliases.
Inherited reading
Inherited reading is supported by default.
static reading method
GetAliases(...) can be obtained from MemberInfo _ Source _, Assembly _ Source _, Module _ Source _, ParameterInfo _ Source _ or object read alias.
Source: framework/Zongsoft.Core/test/Models.cs (excerpt; see source for context).
[DefaultValue(Female)]
public enum Gender : byte
{
[Zongsoft.Components.Alias("F")]
Female,
[Zongsoft.Components.Alias("M")]
[Description("Gender.Male")]
Male,
}Discussions does not declare AliasAttribute directly; this refers to the Gender enumeration in the Core test model. F and M are the aliases of the enumeration members. When reading, GetAliases should be called on the corresponding members, instead of reading the enumeration type and assuming that the aliases of all members can be obtained. This test enum is of a different type than Discussions.Models.Gender.
Usage Suggestions
Aliases are suitable for compatibility with old names, abbreviated names, or external configuration names.
Don't think of an alias as a localized title; it should be a stable, matchable identifier.
Aliases can reduce hard-coded name differences when a component needs to be referenced simultaneously by commands, configurations, plugins, and UI.
If the alias will participate in user input parsing, it is recommended to unify the capitalization and separator conventions to avoid multiple ways of writing the same concept.
Reference Implementation
Last updated