Skip to content

Commit

Permalink
sample updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhitsolutions committed Sep 28, 2018
1 parent 58a8903 commit a05b24f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 17 deletions.
5 changes: 5 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog for PSTypeExtensionTools

## v1.1.0
- Fixed Import-PSTypeExtension bug piping in json/xml files (Issue #13)
- Updated About help documentation
- Modified pipeline processing in Get-PSTypeExtension (Issue #12)

## v1.0.0
- Modified Export-PSTypeExtension to export to a ps1xml file (Issue #11)
- release to the PowerShell Gallery
Expand Down
Binary file modified PSTypeExtensionTools.psd1
Binary file not shown.
22 changes: 16 additions & 6 deletions PSTypeExtensionTools.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@ Function Get-PSTypeExtension {

Begin {
Write-Verbose "Starting: $($MyInvocation.Mycommand)"
}
$typedata=@()
} #begin
Process {
$typedata = Get-TypeData -TypeName $typename
Write-Verbose "Analyzing $typename"
$typedata += Get-TypeData -TypeName $typename


} #process
End {
$typedata = $typedata | Select-Object -Unique
if ($typedata) {

if (-Not $Members) {
Expand Down Expand Up @@ -120,8 +126,6 @@ Function Get-PSTypeExtension {
else {
Write-Warning "Failed to find any type extensions for [$Typename]."
}
}
End {
Write-Verbose "Ending: $($MyInvocation.Mycommand)"
}

Expand Down Expand Up @@ -272,7 +276,10 @@ Function Import-PSTypeExtension {
[string]$Path
)

Begin {
Write-Verbose "Starting: $($myInvocation.mycommand)"
}
Process {
Write-Verbose "Importing file $(Convert-path $Path)"
if ($path -match "\.xml$") {
#xml format seems to add an extra entry
Expand Down Expand Up @@ -300,8 +307,11 @@ Function Import-PSTypeExtension {
Update-TypeData -TypeName $item.Typename -MemberType $item.MemberType -MemberName $item.MemberName -value $value -force
}
} #foreach

Write-Verbose "Ending: $($myInvocation.mycommand)"
}
End {
Write-Verbose "Ending: $($myInvocation.mycommand)"
}

} #end Import-PSTypeExtension

Function Add-PSTypeExtension {
Expand Down
23 changes: 12 additions & 11 deletions docs/about_PSTypeExtensionTools.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# PSTypeExtensionTools
# PSTypeExtensionTools
## about_PSTypeExtensionTools

# SHORT DESCRIPTION
This PowerShell module contains commands that make it easier to work with type
extensions. Many of these commands are wrappers for built-in tools like
Get-TypeData or Update-TypeData. The commands in this module simplfy the
`Get-TypeData` or `Update-TypeData`. The commands in this module simplify the
process of finding, creating, exporting and importing type extensions.

# LONG DESCRIPTION
Expand Down Expand Up @@ -45,7 +45,7 @@ PS C:\> $x.GetPercent(100)
PS C:\> $x.GetPercent(110,4)
34.5455
```
To see what has been defined you can use Get-PSTypeExtension. You can choose to see all extensions or selected ones by member name.
To see what has been defined you can use `Get-PSTypeExtension`. You can choose to see all extensions or selected ones by member name.
```
PS C:\> Get-PSTypeExtension system.int32
Expand All @@ -57,8 +57,8 @@ SquareRoot ScriptProperty [math]::Sqrt($this)
Squared ScriptProperty $this*$this
Cubed ScriptProperty [math]::Pow($this,3)
Value ScriptProperty $this
GetPercent ScriptMethod Param([int32]$Total,[int32]$Round=2) [math]::Round(($this/$total)*100,$round)
```
GetPercent ScriptMethod Param([int32]$Total,[int32]$Round=2) [math]::Round(($this/$total)*100,$round)
```
If you always want these extensions you would have to put the commands into your PowerShell profile script. Or you can export the extensions to a json or xml file. You can either export all members or selected ones which is helpful if you are extending a type that already has type extensions from PowerShell.
```
PS C:\> Get-PSTypeExtension system.int32 -all |
Expand Down Expand Up @@ -88,21 +88,22 @@ Remember to use $this to reference the object and NOT $_.
Remember to enclose scriptblocks in {}.

# SEE ALSO
Add-PSTypeExtension
[Add-PSTypeExtension](./Add-PSTypeExtension.md)

Export-PSTypeExtension
[Export-PSTypeExtension](./Export-PSTypeExtension.md)

Get-PSType
[Get-PSType](./Get-PSType.md)

Get-PSTypeExtension
[Get-PSTypeExtension](./Get-PSTypeExtension.md)

Import-PSTypeExtension
[Import-PSTypeExtension](./Import-PSTypeExtension.md)

Update-TypeData
[Update-TypeData](./Update-TypeData.md)


This project was first described at http://jdhitsolutions.com/blog/powershell/5777/a-powershell-module-for-your-type-extensions

# KEYWORDS
typedata
typeextension
]
6 changes: 6 additions & 0 deletions samples/datetime-extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"MemberType": "ScriptMethod",
"MemberName": "ConvertCulture",
"Value": "Param ([string]$culture)\r\n\r\n\"{0:$([cultureinfo]::GetCultureInfo(\"$culture\").DateTimeFormat.fulldatetimepattern)}\" -f $this",
"TypeName": "System.DateTime"
}

0 comments on commit a05b24f

Please sign in to comment.