@@ -413,6 +413,127 @@ Function Find-LastIndexOf()
413413 }
414414}
415415
416+ Function New-EqualityComparer () {
417+ [CmdletBinding ()]
418+ param (
419+ [Parameter (Mandatory = $false )]
420+ [Alias (" Type" , " t" )]
421+ [ValidateScript ( { $_ -is [type ] -or $_ -is [string ] })]
422+ [object ] $GenericType = " [object]" ,
423+
424+ [Parameter (Mandatory = $true )]
425+ [scriptblock ] $EqualityScript ,
426+
427+ [Parameter (Mandatory = $true )]
428+ [scriptblock ] $HashCodeScript
429+ )
430+
431+ if ($GenericType -is [type ]) {
432+ $GenericType = $GenericType.FullName
433+ }
434+
435+ New-Object - TypeName " ListFunctions.ScriptBlockComparer[$GenericType ]" - Property @ {
436+ EqualityTester = $EqualityScript
437+ HashCodeScript = $HashCodeScript
438+ }
439+ }
440+
441+ Function New-HashSet () {
442+ [CmdletBinding ()]
443+ param (
444+ [Parameter (Mandatory = $false )]
445+ [int ] $Capacity = 1 ,
446+
447+ [Parameter (Mandatory = $false , Position = 0 )]
448+ [Alias (" Type" , " t" )]
449+ [ValidateScript ( { $_ -is [type ] -or $_ -is [string ] })]
450+ [object ] $GenericType = " [object]" ,
451+
452+ [Parameter (Mandatory = $false )]
453+ [ValidateScript ({
454+ $true -in @ (
455+ $_.GetType ().ImplementedInterfaces.FullName | Foreach-Object {
456+ $_ -like " System.Collections.Generic.IEqualityComparer*"
457+ }
458+ )
459+ })]
460+ [object ] $EqualityComparer
461+ )
462+
463+ if ($GenericType -is [type ]) {
464+ $GenericType = $GenericType.FullName
465+ }
466+
467+ if ($PSBoundParameters.ContainsKey (" Capacity" ) -and -not $PSBoundParameters.ContainsKey (" EqualityComparer" ))
468+ {
469+ $set = New-Object - TypeName " System.Collections.Generic.Hashset[$GenericType ]" ($Capacity )
470+ }
471+ elseif (-not $PSBoundParameters.ContainsKey (" Capacity" ) -and $PSBoundParameters.ContainsKey (" EqualityComparer" ))
472+ {
473+ $set = New-Object - TypeName " System.Collections.Generic.Hashset[$GenericType ]" ($EqualityComparer )
474+ }
475+ elseif ($PSBoundParameters.ContainsKey (" Capacity" ) -and $PSBoundParameters.ContainsKey (" EqualityComparer" ))
476+ {
477+ $set = New-Object - TypeName " System.Collections.Generic.Hashset[$GenericType ]" ($Capacity , $EqualityComparer )
478+ }
479+ else {
480+ $set = New-Object - TypeName " System.Collections.Generic.Hashset[$GenericType ]" ($Capacity )
481+ }
482+ , $set
483+ }
484+
485+ Function New-List () {
486+ [CmdletBinding ()]
487+ param
488+ (
489+ [Parameter (Mandatory = $false )]
490+ [Alias (" Type" , " t" )]
491+ [ValidateScript ( { $_ -is [type ] -or $_ -is [string ] })]
492+ [object ] $GenericType = " [object]" ,
493+
494+ [Parameter (Mandatory = $false , Position = 0 )]
495+ [Alias (" c" , " cap" )]
496+ [int ] $Capacity = 1 ,
497+
498+ [Parameter (Mandatory = $false , ValueFromPipeline = $true )]
499+ [object []] $InputObject
500+ )
501+ Begin {
502+
503+ if ($GenericType -is [type ]) {
504+ $private :type = $GenericType
505+ $GenericType = $GenericType.FullName
506+ }
507+
508+ if ($PSBoundParameters.ContainsKey (" Capacity" )) {
509+ $private :list = New-Object " System.Collections.Generic.List[$GenericType ]" ($Capacity )
510+ }
511+ else {
512+ $private :list = New-Object " System.Collections.Generic.List[$GenericType ]"
513+
514+ }
515+ Write-Verbose " List - Created with 'Capacity': $ ( $private :list.Capacity ) "
516+
517+ if ($null -eq $type ) {
518+ $private :type = $private :list.GetType ().GenericTypeArguments[0 ]
519+ }
520+ Write-Verbose " List - GenericType: $ ( $private :type.FullName ) "
521+ $private :type = $private :type.MakeArrayType ()
522+ }
523+ Process {
524+
525+ if ($PSBoundParameters.ContainsKey (" InputObject" )) {
526+
527+ $private :list.AddRange (($InputObject -as $private :type ))
528+ }
529+
530+ }
531+ End {
532+
533+ , $private :list
534+ }
535+ }
536+
416537Function Remove-All ()
417538{
418539 <#
0 commit comments