For the complete documentation index, see llms.txt. This page is also available as Markdown.

Type Aliases

TypeAlias type aliases, generic types, nullable types, and array type resolution.

TypeAlias is used to convert between types and readable strings. It supports built-in type aliases, nullable types, arrays, generic types, assembly shorthand, and nested types.

Common Aliases

TypeAlias provides short names for common CLR types, such as:

Type
Alias example

System.Object

object

System.String

string

System.Int32

int32、int

System.Guid

guid

System.DateOnly

date、dateOnly

System.TimeOnly

time、timeOnly

System.TimeSpan

timeSpan

Parsing Type

Source: framework/Zongsoft.Core/test/Common/TypeAliasTest.cs (excerpt; see source for context).

TypeAliasTest.cs
Assert.Same(typeof(void), TypeAlias.Parse("void"));
Assert.Same(typeof(object), TypeAlias.Parse(" object"));
Assert.Same(typeof(object[]), TypeAlias.Parse("object []"));
Assert.Same(typeof(object), TypeAlias.Parse("System.object"));
Assert.Same(typeof(object[]), TypeAlias.Parse("System.object []"));

Assert.Same(typeof(string), TypeAlias.Parse(" string "));
Assert.Same(typeof(string[]), TypeAlias.Parse("string[ ]"));
Assert.Same(typeof(string), TypeAlias.Parse("System.string"));
Assert.Same(typeof(string[]), TypeAlias.Parse("System.string [ ]"));

Assert.Same(typeof(int), TypeAlias.Parse(" int "));
Assert.Same(typeof(int), TypeAlias.Parse("int32"));
Assert.Same(typeof(int), TypeAlias.Parse("System.Int32"));
Assert.Same(typeof(int?), TypeAlias.Parse("int? "));
Assert.Same(typeof(int[]), TypeAlias.Parse("int [ ] "));
Assert.Same(typeof(int?[]), TypeAlias.Parse(" int?[]"));

Complex types support generics and assembly shorthand.

Source: framework/Zongsoft.Core/test/Common/TypeAliasTest.cs (excerpt; see source for context).

@AssemblyName is the abbreviation of the assembly name, which is equivalent to the common comma assembly qualified form.

Generate Alias

Source: framework/Zongsoft.Core/test/Common/TypeAliasTest.cs (excerpt; see source for context).

GetAlias(assemblyless: true) can omit assembly information and is suitable for displaying only the type name in the current context.

Custom Alias

Custom aliases can be registered via TypeAlias.Aliases.Map.

Custom mappings should be maintained through the registration contract of TypeAlias.Aliases. The current business case does not register a custom type alias; please check the mapping name and type resolution range with TypeAlias source code.

Custom aliases are suitable for short type names in configuration files, scripts, parameter packages, and data model mappings.

This uses the actual assertions from the framework TypeAliasTest, the Zongsoft.Tests type from the test project. Do not copy the test assembly name into the forum's business type configuration.

Last updated