| external help file | PSScriptTools-help.xml |
|---|---|
| Module Name | PSScriptTools |
| online version | https://jdhitsolutions.com/yourls/9825a9 |
| schema | 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 [System.Int32]. This may be a static class or an [Enum].The function has an alias of ctor for convenience. Note there is no period.
PS C:\> $c = ctor system.io.fileinfo
PS C:\> $c | Select-Object *
Type Parameters
---- ----------
System.IO.FileInfo @{ParameterType=string; ParameterName=fileName}
PS C:\ $c.parameters
ParameterType ParameterName
------------- -------------
System.String fileNameView the full details of the constructor.
Specify a .NET type name like DateTime. Beginning with version 3.2.0 you can also specify a value like [DateTime] or [System.IO.FileInfo].
Type: Type
Parameter Sets: (All)
Aliases:
Required: True
Position: 0
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseThis 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