内容简介:.NET 7 Preview 2 已发布,第二个预览版包括对 RegEx 源生成器的增强、将 NativeAOT 从实验状态转移到运行时的进展,以及对“dotnet new”CLI SDK 的一系列重大改进。 在此下载适用于 Windows、macOS 和 Linux 的...
.NET 7 Preview 2 已发布,第二个预览版包括对 RegEx 源生成器的增强、将 NativeAOT 从实验状态转移到运行时的进展,以及对“dotnet new”CLI SDK 的一系列重大改进。
在此下载适用于 Windows、macOS 和 Linux 的 .NET 7 Preview 2 。
引入新的正则表达式源生成器
新的正则表达式源生成器(Issues 44676)在不增加启动成本的情况下,为编译带来了性能好处,还提供了良好的调试体验。
要开始使用新的正则表达式源生成器,只需将包含类型转换为分部(partial
)类型,并使用 RegexGenerator
属性声明一个新的分部方法。该方法将返回优化的 Regex 对象,源生成器将自动填充该方法的实现,并在更改模式或传递其他选项时自动更新。下面是一个例子:
之前:
public class Foo
{
public Regex regex = new Regex(@"abc|def", RegexOptions.IgnoreCase);
public bool Bar(string input)
{
bool isMatch = regex.IsMatch(input);
// ..
}
}
现在:
public partial class Foo // <-- Make the class a partial class
{
[RegexGenerator(@"abc|def", RegexOptions.IgnoreCase)] // <-- Add the RegexGenerator attribute and pass in your pattern and options
public static partial Regex MyRegex(); // <-- Declare the partial method, which will be implemented by the source generator
public bool Bar(string input)
{
bool isMatch = MyRegex().IsMatch(input); // <-- Use the generated engine by invoking the partial method.
// ..
}
}
NativeAOT 更新
该版本将 NativeAOT 从实验性的 dotnet/runtimelab 存储库中移出并进入稳定的运行时库 dotnet/runtime repo,但尚未在 dotnet SDK 中添加足够的支持,以使用 NativeAOT 发布项目。
SDK 改进
-
新的 CLI 解析器 + 选项卡完成 #2191
.NET 新命令为许多子命令提供了更加一致和直观的界面,更新了大量对模板选项和参数的 TAB 补全的支持,在用户输入有效参数和选项时提供快速反馈。以下是新的帮助输出示例:
❯ dotnet new --help
Description:
Template Instantiation Commands for .NET CLI.
Usage:
dotnet new [<template-short-name> [<template-args>...]] [options]
dotnet new [command] [options]
Arguments:
<template-short-name> A short name of the template to create.
<template-args> Template specific options to use.
Options:
-?, -h, --help Show command line help.
Commands:
install <package> Installs a template package.
uninstall <package> Uninstalls a template package.
update Checks the currently installed template packages for update, and install the updates.
search <template-name> Searches for the templates on NuGet.org.
list <template-name> Lists templates containing the specified template name. If no name is specified, lists all templates.
新命令名称
帮助输出中的所有命令不再具有 -- 前缀,更符合用户对 CLI 应用程序中子命令的期望。 旧版本(--install 等)仍可用于防止破坏用户脚本,将来会在这些命令中添加过时警告以鼓励迁移。
Tab 补全
dotnet CLI 在 PowerShell、bash、zsh 和 fish 等流行的 shell 上支持 tab 补全已经有一段时间。 然而,实现有意义的补全取决于单独的 dotnet 命令。 对于 .NET 7,新命令学习了如何提供 Tab 补全:
- 可用的模板名称(在 dotnet new <template-short-name> 中)
❯ dotnet new angular
angular grpc razor viewstart worker -h
blazorserver mstest razorclasslib web wpf /?
blazorwasm mvc razorcomponent webapi wpfcustomcontrollib /h
classlib nugetconfig react webapp wpflib install
console nunit reactredux webconfig wpfusercontrollib list
editorconfig nunit-test sln winforms xunit search
gitignore page tool-manifest winformscontrollib --help uninstall
globaljson proto viewimports winformslib -? update
- 模板选项(Web 模板中的模板选项列表)
dotnet new web --dry-run
--dry-run --language --output -lang
--exclude-launch-settings --name --type -n
--force --no-https -? -o
--framework --no-restore -f /?
--help --no-update-check -h /h
- 模板选项的允许值(选择模板参数上的选择值)
dotnet new blazorserver --auth Individual
Individual IndividualB2C MultiOrg None SingleOrg Windows
该预览版本还有大量其他更新项目,详情请查看更新公告。
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
C++数值算法(第二版)
William T.Vetterling、Brian P.Flannery、Saul A.Teukolsky / 胡健伟、赵志勇、薛运华 / 电子工业出版社 / 2005年01月 / 68.00
本书选材内容丰富,除了通常数值方法课程的内容外,还包含当代科学计算大量用到的专题,如求特殊函数值、随机数、排序、最优化、快速傅里叶变换、谱分析、小波变换、统计描述和数据建模、常微分方程和偏微分方程数值解、若干编码算法和任意精度的计算等。 本书科学性和实用性统一。每个专题中,不仅对每种算法给出了数学分析和比较,而且根据作者的经验对算法做出了评论和建议,并在此基础上给出了用C++语言编写的实用程......一起来看看 《C++数值算法(第二版)》 这本书的介绍吧!
JSON 在线解析
在线 JSON 格式化工具
UNIX 时间戳转换
UNIX 时间戳转换