/
githubmirror
/
PowerShell
Обзор
Документация
Войти
/
githubmirror
/
PowerShell
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/Microsoft.PowerShell.Commands.Utility/commands/utility/NewGuidCommand.cs
58 строк
2 KB
Ahmed Taha
Change New-Guid to generate UUID v7 by default (#27033)
26 июн 2026, 19:25
Не верифицирован
26 июн 2026, 19:25
6f7ffc2
Код
Авторство
О чём код?
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. #nullable enable using System; using System.Management.Automation; namespace Microsoft.PowerShell.Commands { /// <summary> /// The implementation of the "new-guid" cmdlet. /// </summary> [Cmdlet(VerbsCommon.New, "Guid", DefaultParameterSetName = "Default", HelpUri = "https://go.microsoft.com/fwlink/?LinkId=2097130")] [OutputType(typeof(Guid))] public class NewGuidCommand : PSCmdlet { /// <summary> /// Gets or sets a value indicating that the cmdlet should return a Guid structure whose value is all zeros. /// </summary> [Parameter(ParameterSetName = "Empty")] public SwitchParameter Empty { get; set; } /// <summary> /// Gets or sets the value to be converted to a Guid. /// </summary> [Parameter(Position = 0, ValueFromPipeline = true, ParameterSetName = "InputObject")] [System.Diagnostics.CodeAnalysis.AllowNull] public string InputObject { get; set; } /// <summary> /// Returns a Guid. /// </summary> protected override void ProcessRecord() { Guid? guid = null; if (ParameterSetName is "InputObject") { try { guid = new(InputObject); } catch (Exception ex) { ErrorRecord error = new(ex, "StringNotRecognizedAsGuid", ErrorCategory.InvalidArgument, null); WriteError(error); } } else { guid = Empty.ToBool() ? Guid.Empty : Guid.CreateVersion7(); } WriteObject(guid); } } }