external help file | Module Name | online version | schema |
---|---|---|---|
PSScriptTools-help.xml |
PSScriptTools |
2.0.0 |
Get constructor details for a .NET type.
Get-TypeConstructor [-TypeName] <Type> [<CommonParameters>]
Often you need to create a new instance of a .NET type and you need to know what constructors are available. This function will return the constructors for a .NET type. The default output is formatted to display the kind of syntax you would use in your PowerShell code.
PS C:\> Get-TypeConstructor System.Drawing.SolidBrush
[System.Drawing.SolidBrush]::new([System.Drawing.Color]$Color))
The default formatting will using color to highlight the parameter name you would need.
PS C:\> Get-TypeConstructor diagnostics.process
[System.Diagnostics.Process]::new()
This type doesn't need any parameters to create a new instance.
PS C:\> Get-TypeConstructor system.drawing.rectangle
[System.Drawing.Rectangle]::new([System.Int32]$X),
[System.Int32]$Y),
[System.Int32]$Width),
[System.Int32]$Height))
[System.Drawing.Rectangle]::new([System.Drawing.Point]$Location),[System.Drawing.Size]$Size))
Constructors with more than three parameters will be displayed in a list to make it easier to read.
PS C:\> ctor int32
WARNING: No constructors found for Int32
The function has an alias of ctor for convenience. Note there is no period.
Specify a .NET type name like DateTime
Type: Type
Parameter Sets: (All)
Aliases:
Required: True
Position: 0
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
Learn more about PowerShell: https://jdhitsolutions.com/yourls/newsletter