Moving New-Guid to compiled cmdlet#2752
Moving New-Guid to compiled cmdlet#2752
Conversation
|
Hi @powercode, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution! The agreement was validated by Microsoft and real humans are currently evaluating your PR. TTYL, MSBOT; |
There was a problem hiding this comment.
Empty should be all zeros. Fixed.
There was a problem hiding this comment.
We indent with spaces, not tabs.
There was a problem hiding this comment.
How I wish that tab/spaces was a per project setting in VS...
DICE has tabs, and switching back and forth is a mess...
There was a problem hiding this comment.
The cmdlet suggests that it creates a new object every time it's called, but with this parameter, nothing is actually created.
There was a problem hiding this comment.
Well, you have noting before, and after you have a guid. Admittedly a static one that will never change, but it is friendlier to type new-guid -e than [guid]::empty, especially with Scandinavian keyboards, where '[' is on AltGr+8.
But it's your call. Remove?
There was a problem hiding this comment.
This code feels like it doesn't belong in a cmdlet with the verb New, and I don't think we want a cmdlet Convert-ToGuid.
There was a problem hiding this comment.
(Copy from Issue) Some applications use GUID as a unique identifier. In this case, the identifier is a string. So really, we can get a stream of strings (ex. from logs), that we want to convert to [guid] . And yes this is more for ConvertTo-Guid but I looked through New-* cmdlets and many of them do a similar operation (string -> object). Most likely the new ConvertTo-Guid cmdlet is redundant and perhaps it would be better to make the GUID parameter.
5368d9b to
73e2706
Compare
73e2706 to
065f5e9
Compare
There was a problem hiding this comment.
You don't need to update map.json for new files.
065f5e9 to
b25a1d5
Compare
There was a problem hiding this comment.
It seems this parameter is redundant.
The only cmdlet that uses Count parameter is Get-Random and only to determines how many objects are returned from input pipeline.
Usually we do so:
0..9 | New-GuidThere was a problem hiding this comment.
Well, to me, that looks like the input in some way should be related to the created guids.
There was a problem hiding this comment.
Yes, the sample is incorrect.
I mean:
0..10 | % { Get-Random }There was a problem hiding this comment.
Most likely you had in mind:
if (String.Equals(ParameterSetName, "Empty", StringComparison.OrdinalIgnoreCase))
or
if (ParameterSetName == "Empty")
There was a problem hiding this comment.
Well, the empty switch will only be on if the parameterset is "Empty" so it seems like a cheaper and simpler test. They are functionally equivalent, but I think this is easier to read
There was a problem hiding this comment.
Using if (Empty) here will also handle a rare usage of the cmdlet: New-Guid -Empty:$false -- it will write out a new GUID in that case.
There was a problem hiding this comment.
This comment probably should be Return one or more guids.
|
Don't merge yet - I've marked this for committee review. I personally wouldn't mind removing this command, or if we do, it should work just like the existing function, nothing more, but we should decide that as a committee. |
|
I analyzed using I manually inspected these scripts. A common usage (in descending order of popularity): $GUID = (New-Guid).Guid
[string]$Name = (New-Guid).ToString()
$id = New-Guid
$name = "Solution_$id"
$wpconfig = $wpconfig.Replace("eisauthkey",$(New-Guid))
function New-Guid {
[System.Guid]::NewGuid().ToString("d").Substring(0, 4).Replace("-", "")
}
$guid = (New-Guid).GUID.Replace("-","_") |
b25a1d5 to
00ff6eb
Compare
| /// <summary> | ||
| /// returns a guid | ||
| /// </summary> | ||
| protected override void EndProcessing() |
There was a problem hiding this comment.
EndProcessing [](start = 32, length = 13)
this implementation subtly changes the current implementation (the function uses Begin rather than End as is here) - I don't believe it to be a big problem, but thought I should add the note
There was a problem hiding this comment.
This is intentional, see this discussion: https://github.com/PowerShell/PowerShell/pull/2786/files/48a6fb2e05c6d4954f94d9f34139ff338aae41a2#r89893087
|
@PowerShell/powershell-committee we discussed this and for discovery reasons as well as shipping this previously, we should have new-guid even though it's a simple operation for users familiar with the guid class |
Fixing #2733
Simplest implementation possible