diff --git a/MyNumber.psd1 b/MyNumber.psd1 index ae16722..ca8d10c 100644 Binary files a/MyNumber.psd1 and b/MyNumber.psd1 differ diff --git a/MyNumber.psm1 b/MyNumber.psm1 index 9b00984..a75a4d7 100644 --- a/MyNumber.psm1 +++ b/MyNumber.psm1 @@ -1,11 +1,8 @@ -#requires -version 5.0 - #region Main #define class - Class MyNumber { - + #properties [double]$Number [double]$Square [double]$Cube @@ -21,14 +18,12 @@ Class MyNumber { [double]$Exp [double]$Factorial [double[]]$Factors - [psobject]$Custom + [PSObject]$Custom #store the custom scriptblock in a hidden property which can be managed through a module function hidden [scriptblock]$CustomScriptBlock #methods - - [mynumber] Refresh() { - + [MyNumber] Refresh() { $this.Square = ($this.number * $this.number) $this.Cube = [math]::Pow($this.number, 3) $this.Sqrt = [math]::Sqrt($this.number) @@ -39,18 +34,18 @@ Class MyNumber { $this.CircleArea = [math]::PI * ($this.number * $this.number) $this.Inverse = 1 / $this.number $this.Exp = [math]::Exp($this.number) - $this.Factorial = (1..$this.number | foreach-object -begin {$r = 1} -process {$r *= $_} -end {$r}) - $this.Factors = (1..$($this.number) | where-object {-Not ($this.number % $_)}) + $this.Factorial = (1..$this.number | ForEach-Object -Begin { $r = 1 } -Process { $r *= $_ } -End { $r }) + $this.Factors = (1..$($this.number) | Where-Object { -Not ($this.number % $_) }) $this.IsEven = $this.TestIsEven() $this.IsPrime = $this.TestIsPrime() if ($this.CustomScriptBlock) { - $customresult = Invoke-Command -ScriptBlock $this.CustomScriptBlock -ArgumentList $this.Number + $CustomResult = Invoke-Command -ScriptBlock $this.CustomScriptBlock -ArgumentList $this.Number } else { - $customresult = 0 + $CustomResult = 0 } - $this.Custom = $customresult - + $this.Custom = $CustomResult + #class methods require the Return keyword Return $this } @@ -71,17 +66,17 @@ Class MyNumber { Return $False } } - [string]ToBinary() { + [String]ToBinary() { $r = [convert]::ToString($this.Number, 2) Return $r } - [string]ToOctal() { + [String]ToOctal() { $r = [convert]::ToString($this.Number, 8) Return $r } - [string]ToHex() { + [String]ToHex() { $r = [convert]::ToString($this.Number, 16) Return $r } @@ -93,94 +88,14 @@ Class MyNumber { } } -#endregion - -Function New-MyNumber { - [CmdletBinding()] - [OutputType([MyNumber])] - - Param( - [Parameter(Position = 0, Mandatory, HelpMessage = "Enter a numeric value.", ValueFromPipeline)] - [double[]]$Number, - [scriptblock]$CustomScriptBlock - ) - Process { - Foreach ($n in $Number) { - Write-Verbose "Creating a myNumber object for $n" - $obj = New-Object -TypeName MyNumber -ArgumentList $n - - if ($CustomScriptBlock) { - $obj.CustomScriptBlock = $CustomScriptBlock - $obj.Refresh() | out-Null - } - $obj - } - } -} - -Function Convert-MyNumber { - [CmdletBinding(defaultparametersetname = 'binary')] - [OutputType([System.String])] - - Param( - [Parameter(Position = 0, ValueFromPipelineByPropertyName, ValueFromPipeline, Mandatory)] - [Double]$Number, - [Parameter(ParameterSetName = "binary")] - [Switch]$ToBinary, - [Parameter(ParameterSetName = "hex")] - [Switch]$ToHex, - [Parameter(ParameterSetName = "octal")] - [Switch]$ToOctal - ) - Begin { } - Process { - Write-Verbose "Processing $number" - Switch ($PSCmdlet.ParameterSetName) { - "binary" { - [convert]::ToString($Number, 2) - } - "hex" { - [convert]::ToString($Number, 16) - } - "octal" { - [convert]::ToString($Number, 8) - } - } - } - End {} -} +#extend the class with custom type extensions -Function Set-MyNumber { - [cmdletbinding(SupportsShouldProcess, DefaultParameterSetName = "value")] - [OutputType([MyNumber])] +Update-TypeData -TypeName MyNumber -MemberType ScriptProperty -MemberName Computername -Value {[System.Environment]::MachineName} -Force - Param( - [Parameter(Position = 0, ValueFromPipeline, Mandatory)] - [MyNumber]$Number, - [Parameter(Position = 1, Mandatory, ParameterSetName = "Value")] - [double]$Value, - [Parameter(ParameterSetName = "script")] - [scriptblock]$CustomScriptBlock - ) - Begin {} - Process { +Update-TypeData -TypeName MyNumber -MemberType AliasProperty -MemberName Value -Value Number -Force - switch ($pscmdlet.ParameterSetName) { - "value" { - if ($pscmdlet.ShouldProcess("MyNumber", "Set number to $value")) { - $number.number = $Value - $number.refresh() - } - } #value - "script" { - if ($pscmdlet.ShouldProcess("MyNumber", "Set custom script to $CustomScriptblock")) { - $number.CustomScriptBlock = $CustomScriptBlock - $number.refresh() - } - } - } - } - End {} -} +#endregion +#dot source module functions +Get-ChildItem -Path $PSScriptRoot\functions\*.ps1 | ForEach-Object -Process { . $_.FullName } \ No newline at end of file diff --git a/README.md b/README.md index 0aad26c..799a749 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # MyNumber -A demonstration class-based module that creates a *number* object. The functionality of the module isn't that practical. But it can serve as a model on how you might build a class-based PowerShell tool. +:mortar_board: A demonstration class-based module that creates a *number* object. The functionality of the module isn't that practical. But it can serve as a model of how you might build a class-based PowerShell tool. -The module should work on Windows PowerShell and PowerShell Core cross-platform. It is intended for educational purposes. +The module should work on Windows PowerShell and PowerShell 7, including cross-platform. It is intended for educational purposes. Install the latest version from the PowerShell Gallery. @@ -10,16 +10,23 @@ Install the latest version from the PowerShell Gallery. Install-Module MyNumber ``` -In PowerShell Core you'll most likely need to include `-scope currentuser`. +You can also use the `Microsoft.PowerShell.PSResourceGet` module. + +```powershell +Install-PSResource MyNumber -scope AllUsers +``` The class is defined in [MyNumber.psm1](mynumber.psm1). Functionality is exposed through a set of functions. -+ [New-MyNumber](./docs/New-MyNumber.md) -+ [Set-MyNumber](./docs/Set-MyNumber.md) -+ [Convert-MyNumber](./docs/Convert-MyNumber.md) ++ [New-MyNumber](/docs/New-MyNumber.md) ++ [Set-MyNumber](/docs/Set-MyNumber.md) ++ [Convert-MyNumber](/docs/Convert-MyNumber.md) + +The module also includes custom format and type extensions. The examples shown below may not reflect these changes. + ```powershell -PS C:\> $x = new-mynumber 11 +PS C:\> $x = New-MyNumber 11 PS C:\> $x @@ -40,7 +47,7 @@ Factorial : 39916800 Factors : {1, 11} Custom : 0 -PS C:\> $x | Set-mynumber -value 123 +PS C:\> $x | Set-MyNumber -value 123 Number : 123 @@ -60,17 +67,17 @@ Factorial : 1.21463043670253E+205 Factors : {1, 3, 41, 123} Custom : 0 -PS C:\> $x | convert-mynumber -tohex +PS C:\> $x | Convert-MyNumber -ToHex 7b -PS C:\> convert-mynumber 1024 -ToBinary +PS C:\> Convert-MyNumber 1024 -ToBinary 10000000000 ``` -You can also create a number with a custom scriptblock. +You can also create a number with a custom script block. ```powershell -PS C:\> new-mynumber 77 -CustomScriptBlock {Param($x) [char][int]$x } +PS C:\> New-MyNumber 77 -CustomScriptBlock {Param($x) [char][int]$x } Number : 77 @@ -91,8 +98,6 @@ Factors : {1, 7, 11, 77} Custom : M ``` -You should include a parameter in your scriptblock for the number value. It will be passed as an argument when calculating the value. +You should include a parameter in your script block for the number value. It will be passed as an argument when calculating the value. You can only access the class definition through the functions. - -_Last updated 23 October 2018_ \ No newline at end of file diff --git a/Tests/MyNumber.tests.ps1 b/Tests/MyNumber.tests.ps1 index 32992ca..ae05f2a 100644 --- a/Tests/MyNumber.tests.ps1 +++ b/Tests/MyNumber.tests.ps1 @@ -1,37 +1,44 @@ +#this is an incomplete Pester test + Import-Module $PSScriptRoot\..\MyNumber.psd1 -Force Describe New-MyNumber { + $Test = @( + @{Property = 'Cube'; Type = 'double' } + @{Property = 'Sine'; Type = 'double' } + @{Property = 'Sqrt'; Type = 'double' } + @{Property = 'Inverse'; Type = 'double' } + @{Property = 'IsPrime'; Type = 'bool' } + @{Property = 'CircleArea'; Type = 'double' } + @{Property = 'Cosine'; Type = 'double' } + @{Property = 'Square'; Type = 'double' } + @{Property = 'Log'; Type = 'double' } + @{Property = 'Tangent'; Type = 'double' } + @{Property = 'IsEven'; Type = 'bool' } + @{Property = 'Number'; Type = 'double' } + @{Property = 'Factors'; Type = 'double[]' } + @{Property = 'Factorial'; Type = 'double' } + @{Property = 'Exp'; Type = 'double' } + ) + + BeforeAll { + $n = New-MyNumber 1 + } + It 'Should run without error' { - { New-MyNumber 1 } | Should -Not Throw + { New-MyNumber -Number 1 } | Should -Not -Throw } It 'Should create a MyNumber object type' { - $n = New-MyNumber 1 $n.GetType().Name | Should -Be 'MyNumber' } - $PropHash = @{ - Log = [double] - Number = [double] - Sqrt = [double] - IsEven = [bool] - IsPrime = [bool] - Cosine = [double] - Factorial = [double] - Exp = [double] - Inverse = [double] - Sine = [double] - Square = [double] - CircleArea = [double] - Tangent = [double] - Factors = [double[]] - Cube = [double] - } - $PropHash.GetEnumerator() | ForEach-Object -Begin { $n = New-MyNumber 2 } -Process { - It "Should have a property called $($_.key) of type $($_.value)" { - $n.$($_.key) -is $_.value | Should -Be $True - } + + It 'Should have a property called with a type of ' -ForEach $Test { + + $n.PSObject.Properties[$Property].TypeNameOfValue | Should -Be ($Type -As [Type]).FullName } + It 'Should create a new object with pipeline input' { (1..5 | New-MyNumber).count | Should -Be 5 } diff --git a/Docs/Convert-MyNumber.md b/docs/Convert-MyNumber.md similarity index 93% rename from Docs/Convert-MyNumber.md rename to docs/Convert-MyNumber.md index 5d37d8d..8dddd52 100644 --- a/Docs/Convert-MyNumber.md +++ b/docs/Convert-MyNumber.md @@ -40,7 +40,7 @@ Convert a numeric value to the specified format. The result will be a string. ### Example 1 ```powershell -PS C:\> convert-mynumber 123 +PS C:\> Convert-MyNumber 123 1111011 ``` @@ -49,14 +49,14 @@ The default behavior is to convert to binary. ### Example 2 ```powershell -PS C:\> 1024678 | convert-mynumber -ToHex +PS C:\> 1024678 | Convert-MyNumber -ToHex fa2a6 ``` ### Example 3 ```powershell -PS C:\> 1024678 | convert-mynumber -ToOctal +PS C:\> 1024678 | Convert-MyNumber -ToOctal 3721246 ``` diff --git a/Docs/New-MyNumber.md b/docs/New-MyNumber.md similarity index 85% rename from Docs/New-MyNumber.md rename to docs/New-MyNumber.md index d06c0ab..9daabdc 100644 --- a/Docs/New-MyNumber.md +++ b/docs/New-MyNumber.md @@ -65,7 +65,7 @@ Number Square Cube ### Example 3 ```powershell -PS C:\> new-mynumber 77 -CustomScriptBlock {Param($x) [char][int]$x } +PS C:\> New-MyNumber 77 -CustomScriptBlock {Param($x) [char][int]$x } Number : 77 @@ -86,7 +86,7 @@ Factors : {1, 7, 11, 77} Custom : M ``` -Here is an example using a custom scriptblock. You should include a parameter in your scriptblock for the number value. +Here is an example using a custom script block. You should include a parameter in your script block for the number value. ## PARAMETERS @@ -108,7 +108,7 @@ Accept wildcard characters: False ### -CustomScriptBlock -You can specify a custom scriptblock that can be used to calculate a custom value. You should use a scriptblock with a parameter indicating the current number. When the scriptblock is executed the number value is passed as an argument. See examples. +You can specify a custom script block that can be used to calculate a custom value. You should use a script block with a parameter indicating the current number. When the scrip tblock is executed the number value is passed as an argument. See examples. ```yaml Type: ScriptBlock diff --git a/Docs/Set-MyNumber.md b/docs/Set-MyNumber.md similarity index 90% rename from Docs/Set-MyNumber.md rename to docs/Set-MyNumber.md index 6b86ff3..08a1706 100644 --- a/Docs/Set-MyNumber.md +++ b/docs/Set-MyNumber.md @@ -40,7 +40,7 @@ Use this command to update a MyNumber object with a new value. ### Example 1 ```powershell -PS C:\> $x = New-Mynumber 52 +PS C:\> $x = New-MyNumber 52 PS C:\> $x @@ -61,7 +61,7 @@ Factorial : 8.06581751709439E+67 Factors : {1, 2, 4, 13...} Custom : 0 -PS C:\> $x | set-mynumber -value 111 +PS C:\> $x | Set-MyNumber -value 111 Number : 111 @@ -107,7 +107,7 @@ Factors : {1, 2, 4, 13...} Custom : 14 ``` -Set a custom scriptblock. You should include a parameter in your scriptblock for the number value. +Set a custom scrip block. You should include a parameter in your script lock for the number value. ## PARAMETERS @@ -177,7 +177,7 @@ Accept wildcard characters: False ### -CustomScriptBlock -You can specify a custom scriptblock that can be used to calculate a custom value. You should use a scriptblock with a parameter indicating the current number. When the scriptblock is executed the number value is passed as an argument. See examples. +You can specify a custom script block that can be used to calculate a custom value. You should use a script block with a parameter indicating the current number. When the script block is executed the number value is passed as an argument. See examples. ```yaml Type: ScriptBlock diff --git a/en-US/MyNumber-help.xml b/en-US/MyNumber-help.xml index 51c3d2d..a6d5db9 100644 --- a/en-US/MyNumber-help.xml +++ b/en-US/MyNumber-help.xml @@ -17,9 +17,9 @@ Convert-MyNumber Number - + A numeric value to be converted. - + Double Double @@ -29,9 +29,9 @@ ToBinary - + Convert the number to a binary string - + SwitchParameter @@ -43,9 +43,9 @@ Convert-MyNumber Number - + A numeric value to be converted. - + Double Double @@ -55,9 +55,9 @@ ToHex - + Convert the number to a hex string - + SwitchParameter @@ -69,9 +69,9 @@ Convert-MyNumber Number - + A numeric value to be converted. - + Double Double @@ -81,9 +81,9 @@ ToOctal - + Convert the number to an Octal string - + SwitchParameter @@ -95,9 +95,9 @@ Number - + A numeric value to be converted. - + Double Double @@ -107,9 +107,9 @@ ToBinary - + Convert the number to a binary string - + SwitchParameter SwitchParameter @@ -119,9 +119,9 @@ ToHex - + Convert the number to a hex string - + SwitchParameter SwitchParameter @@ -131,9 +131,9 @@ ToOctal - + Convert the number to an Octal string - + SwitchParameter SwitchParameter @@ -170,7 +170,7 @@ -------------------------- Example 1 -------------------------- - PS C:\> convert-mynumber 123 + PS C:\> Convert-MyNumber 123 1111011 The default behavior is to convert to binary. @@ -178,7 +178,7 @@ -------------------------- Example 2 -------------------------- - PS C:\> 1024678 | convert-mynumber -ToHex + PS C:\> 1024678 | Convert-MyNumber -ToHex fa2a6 @@ -186,7 +186,7 @@ fa2a6 -------------------------- Example 3 -------------------------- - PS C:\> 1024678 | convert-mynumber -ToOctal + PS C:\> 1024678 | Convert-MyNumber -ToOctal 3721246 @@ -221,9 +221,9 @@ fa2a6 New-MyNumber Number - + Enter a numeric value. - + Double[] Double[] @@ -233,9 +233,9 @@ fa2a6 CustomScriptBlock - - You can specify a custom scriptblock that can be used to calculate a custom value. You should use a scriptblock with a parameter indicating the current number. When the scriptblock is executed the number value is passed as an argument. See examples. - + + You can specify a custom script block that can be used to calculate a custom value. You should use a script block with a parameter indicating the current number. When the scrip tblock is executed the number value is passed as an argument. See examples. + ScriptBlock ScriptBlock @@ -248,9 +248,9 @@ fa2a6 Number - + Enter a numeric value. - + Double[] Double[] @@ -260,9 +260,9 @@ fa2a6 CustomScriptBlock - - You can specify a custom scriptblock that can be used to calculate a custom value. You should use a scriptblock with a parameter indicating the current number. When the scriptblock is executed the number value is passed as an argument. See examples. - + + You can specify a custom script block that can be used to calculate a custom value. You should use a script block with a parameter indicating the current number. When the scrip tblock is executed the number value is passed as an argument. See examples. + ScriptBlock ScriptBlock @@ -338,7 +338,7 @@ Number Square Cube -------------------------- Example 3 -------------------------- - PS C:\> new-mynumber 77 -CustomScriptBlock {Param($x) [char][int]$x } + PS C:\> New-MyNumber 77 -CustomScriptBlock {Param($x) [char][int]$x } Number : 77 @@ -358,7 +358,7 @@ Factorial : 1.45183092028286E+113 Factors : {1, 7, 11, 77} Custom : M - Here is an example using a custom scriptblock. You should include a parameter in your scriptblock for the number value. + Here is an example using a custom script block. You should include a parameter in your script block for the number value. @@ -386,9 +386,9 @@ Custom : M Set-MyNumber Number - + A MyNumber object. - + MyNumber MyNumber @@ -398,9 +398,9 @@ Custom : M Value - + The new value for the Number value. - + Double Double @@ -410,9 +410,9 @@ Custom : M Confirm - + Prompts you for confirmation before running the cmdlet. - + SwitchParameter @@ -421,9 +421,9 @@ Custom : M WhatIf - + Shows what would happen if the cmdlet runs. The cmdlet is not run. - + SwitchParameter @@ -435,9 +435,9 @@ Custom : M Set-MyNumber Number - + A MyNumber object. - + MyNumber MyNumber @@ -447,9 +447,9 @@ Custom : M Confirm - + Prompts you for confirmation before running the cmdlet. - + SwitchParameter @@ -458,9 +458,9 @@ Custom : M WhatIf - + Shows what would happen if the cmdlet runs. The cmdlet is not run. - + SwitchParameter @@ -469,9 +469,9 @@ Custom : M CustomScriptBlock - - You can specify a custom scriptblock that can be used to calculate a custom value. You should use a scriptblock with a parameter indicating the current number. When the scriptblock is executed the number value is passed as an argument. See examples. - + + You can specify a custom script block that can be used to calculate a custom value. You should use a script block with a parameter indicating the current number. When the script block is executed the number value is passed as an argument. See examples. + ScriptBlock ScriptBlock @@ -484,9 +484,9 @@ Custom : M Number - + A MyNumber object. - + MyNumber MyNumber @@ -496,9 +496,9 @@ Custom : M Value - + The new value for the Number value. - + Double Double @@ -508,9 +508,9 @@ Custom : M Confirm - + Prompts you for confirmation before running the cmdlet. - + SwitchParameter SwitchParameter @@ -520,9 +520,9 @@ Custom : M WhatIf - + Shows what would happen if the cmdlet runs. The cmdlet is not run. - + SwitchParameter SwitchParameter @@ -532,9 +532,9 @@ Custom : M CustomScriptBlock - - You can specify a custom scriptblock that can be used to calculate a custom value. You should use a scriptblock with a parameter indicating the current number. When the scriptblock is executed the number value is passed as an argument. See examples. - + + You can specify a custom script block that can be used to calculate a custom value. You should use a script block with a parameter indicating the current number. When the script block is executed the number value is passed as an argument. See examples. + ScriptBlock ScriptBlock @@ -571,7 +571,7 @@ Custom : M -------------------------- Example 1 -------------------------- - PS C:\> $x = New-Mynumber 52 + PS C:\> $x = New-MyNumber 52 PS C:\> $x @@ -592,7 +592,7 @@ Factorial : 8.06581751709439E+67 Factors : {1, 2, 4, 13...} Custom : 0 -PS C:\> $x | set-mynumber -value 111 +PS C:\> $x | Set-MyNumber -value 111 Number : 111 @@ -636,7 +636,7 @@ Factorial : 8.06581751709439E+67 Factors : {1, 2, 4, 13...} Custom : 14 - Set a custom scriptblock. You should include a parameter in your scriptblock for the number value. + Set a custom scrip block. You should include a parameter in your script lock for the number value. diff --git a/formats/mynumber.format.ps1xml b/formats/mynumber.format.ps1xml new file mode 100644 index 0000000..acf37f8 --- /dev/null +++ b/formats/mynumber.format.ps1xml @@ -0,0 +1,91 @@ + + + + + + default + + MyNumber + + + + Number + + + + + + + + + + Square + + + + Cube + + + + Sqrt + + + + Log + + + + Sine + + + + Cosine + + + + Tangent + + + + CircleArea + + + + Inverse + + + + Exp + + + + Factorial + + + + Factors + + + + + + + + \ No newline at end of file diff --git a/functions/Convert-MyNumber.ps1 b/functions/Convert-MyNumber.ps1 new file mode 100644 index 0000000..b7f2858 --- /dev/null +++ b/functions/Convert-MyNumber.ps1 @@ -0,0 +1,32 @@ +Function Convert-MyNumber { + [CmdletBinding(DefaultParameterSetName = 'binary')] + [OutputType([System.String])] + + Param( + [Parameter(Position = 0, ValueFromPipelineByPropertyName, ValueFromPipeline, Mandatory)] + [Double]$Number, + [Parameter(ParameterSetName = 'binary')] + [Switch]$ToBinary, + [Parameter(ParameterSetName = 'hex')] + [Switch]$ToHex, + [Parameter(ParameterSetName = 'octal')] + [Switch]$ToOctal + ) + + Begin { } + Process { + Write-Verbose "Processing $number" + Switch ($PSCmdlet.ParameterSetName) { + 'binary' { + [convert]::ToString($Number, 2) + } + 'hex' { + [convert]::ToString($Number, 16) + } + 'octal' { + [convert]::ToString($Number, 8) + } + } + } + End {} +} diff --git a/functions/New-MyNumber.ps1 b/functions/New-MyNumber.ps1 new file mode 100644 index 0000000..ff02321 --- /dev/null +++ b/functions/New-MyNumber.ps1 @@ -0,0 +1,22 @@ +Function New-MyNumber { + [CmdletBinding()] + [OutputType('MyNumber')] + + Param( + [Parameter(Position = 0, Mandatory, HelpMessage = 'Enter a numeric value.', ValueFromPipeline)] + [double[]]$Number, + [scriptblock]$CustomScriptBlock + ) + Process { + Foreach ($n in $Number) { + Write-Verbose "Creating a myNumber object for $n" + $obj = New-Object -TypeName MyNumber -ArgumentList $n + + if ($CustomScriptBlock) { + $obj.CustomScriptBlock = $CustomScriptBlock + $obj.Refresh() | Out-Null + } + $obj + } + } +} diff --git a/functions/Set-MyNumber.ps1 b/functions/Set-MyNumber.ps1 new file mode 100644 index 0000000..d8c8240 --- /dev/null +++ b/functions/Set-MyNumber.ps1 @@ -0,0 +1,31 @@ +Function Set-MyNumber { + [CmdletBinding(SupportsShouldProcess, DefaultParameterSetName = 'value')] + [OutputType('MyNumber')] + + Param( + [Parameter(Position = 0, ValueFromPipeline, Mandatory)] + [MyNumber]$Number, + [Parameter(Position = 1, Mandatory, ParameterSetName = 'Value')] + [double]$Value, + [Parameter(ParameterSetName = 'script')] + [scriptblock]$CustomScriptBlock + ) + Begin {} + Process { + switch ($PSCmdlet.ParameterSetName) { + 'value' { + if ($PSCmdlet.ShouldProcess('MyNumber', "Set number to $value")) { + $number.number = $Value + $number.refresh() + } + } #value + 'script' { + if ($PSCmdlet.ShouldProcess('MyNumber', "Set custom script to $CustomScriptblock")) { + $number.CustomScriptBlock = $CustomScriptBlock + $number.refresh() + } + } + } + } + End {} +} diff --git a/types/mynumber.types.ps1xml b/types/mynumber.types.ps1xml new file mode 100644 index 0000000..6064507 --- /dev/null +++ b/types/mynumber.types.ps1xml @@ -0,0 +1,26 @@ + + + + + MyNumber + + + trig + + Value + Sine + Cosine + Tangent + + + + + \ No newline at end of file