Closed gaufung closed 2 weeks ago
这是 C# 新功能介绍的一系列文章,主要介绍了 Alias Any Type
的功能。不同于之前的功能介绍,这次作者按照一个具体的 demo 展示如何使用这个功能,大部分内容在 GlobalUsing.cs
文件中
// Ensures that all types within these namespaces are globally available.
global using Alias.AnyType;
global using Alias.AnyType.Extensions;
global using Alias.AnyType.ResponseModels;
// Expose all static members of math.
global using static System.Math;
// Alias a coordinates object.
global using Coordinates = (double Latitude, double Longitude);
// Alias representation of degrees-minutes-second (DMS).
global using DMS = (int Degree, int Minute, double Second);
// Alias representation of various distances in different units of measure.
global using Distance = (double Meters, double Kilometers, double Miles);
// Alias a stream of coordinates represented as an async enumerable.
global using CoordinateStream = System.Collections.Generic.IAsyncEnumerable<
Alias.AnyType.CoordinateGeoCodePair>;
// Alias the CTS, making it simply "Signal".
global using Signal = System.Threading.CancellationTokenSource;
global using Alias.AnyType
可以导入这个 namespace
下所有成员global using static System.Match
可以导出这个命令空间下的静态成员global using DMS = (int Degree, int Minute, double Second)
将一个 Tuple
类型使用 DMS
别名global using Signal = System.Threading.CancellationTokenSource
是将一个系统类型 CancellationTokenSource
使用 Signal
别名
https://devblogs.microsoft.com/dotnet/refactor-your-code-using-alias-any-type/