|
20 | 20 | .Example |
21 | 21 | # This will render the property 'Status' of the current object, |
22 | 22 | # if the current object's 'Complete' property is $false. |
23 | | - Write-FormatViewExpression -Property Status -If { -not $_.Complete } |
24 | | -
|
| 23 | + Write-FormatViewExpression -Property Status -If { -not $_.Complete } |
25 | 24 | #> |
26 | 25 | [CmdletBinding(DefaultParameterSetName='ScriptBlock')] |
27 | 26 | [OutputType([string])] |
28 | 27 | [Alias('Show-CustomAction')] |
29 | 28 | param( |
30 | 29 | # The name of the control. If this is provided, it will be used to display the property or script block. |
31 | | - [Parameter(ValueFromPipelineByPropertyName=$true)] |
| 30 | + [Parameter(ValueFromPipelineByPropertyName)] |
32 | 31 | [Alias('ActionName','Name')] |
33 | 32 | [String] |
34 | 33 | $ControlName, |
35 | 34 |
|
36 | 35 | # If a property name is provided, then the custom action will show the contents |
37 | 36 | # of the property |
38 | | - [Parameter(Mandatory=$true,ParameterSetName='Property',Position=0,ValueFromPipelineByPropertyName=$true)] |
| 37 | + [Parameter(Mandatory=$true,ParameterSetName='Property',Position=0,ValueFromPipelineByPropertyName)] |
39 | 38 | [Alias('PropertyName')] |
40 | 39 | [String] |
41 | 40 | $Property, |
42 | 41 |
|
43 | 42 | # If a script block is provided, then the custom action shown in formatting |
44 | 43 | # will be the result of the script block. |
45 | | - [Parameter(Mandatory=$true,ParameterSetName='ScriptBlock',Position=0,ValueFromPipelineByPropertyName=$true)] |
| 44 | + [Parameter(Mandatory=$true,ParameterSetName='ScriptBlock',Position=0,ValueFromPipelineByPropertyName)] |
46 | 45 | [ScriptBlock] |
47 | 46 | $ScriptBlock, |
48 | 47 |
|
|
53 | 52 | $If, |
54 | 53 |
|
55 | 54 | # If provided, will output the provided text. All other parameters are ignored. |
56 | | - [Parameter(Mandatory,ParameterSetName='Text',ValueFromPipelineByPropertyName=$true)] |
| 55 | + [Parameter(Mandatory,ParameterSetName='Text',ValueFromPipelineByPropertyName)] |
57 | 56 | [string] |
58 | 57 | $Text, |
59 | 58 |
|
|
73 | 72 | $ResourceID, |
74 | 73 |
|
75 | 74 | # If provided, will output a <NewLine /> element. All other parameters are ignored. |
76 | | - [Parameter(Mandatory=$true,ParameterSetName='NewLine',ValueFromPipelineByPropertyName=$true)] |
| 75 | + [Parameter(Mandatory=$true,ParameterSetName='NewLine',ValueFromPipelineByPropertyName)] |
77 | 76 | [switch] |
78 | 77 | $Newline, |
79 | 78 |
|
| 79 | + # If set, will put the expression within a <Frame> element. |
| 80 | + [Parameter(ValueFromPipelineByPropertyName)] |
| 81 | + [switch] |
| 82 | + $Frame, |
| 83 | + |
| 84 | + # If provided, will indent by a number of characters. This implies -Frame. |
| 85 | + [Parameter(ValueFromPipelineByPropertyName)] |
| 86 | + [Alias('Indent')] |
| 87 | + [ValidateRange(0,1mb)] |
| 88 | + [int] |
| 89 | + $LeftIndent, |
| 90 | + |
| 91 | + # If provided, will indent the right by a number of characters. This implies -Frame. |
| 92 | + [Parameter(ValueFromPipelineByPropertyName)] |
| 93 | + [ValidateRange(0,1mb)] |
| 94 | + [int] |
| 95 | + $RightIndent, |
| 96 | + |
| 97 | + # Specifies how many characters the first line of data is shifted to the left. This implies -Frame. |
| 98 | + [Parameter(ValueFromPipelineByPropertyName)] |
| 99 | + [ValidateRange(0,1mb)] |
| 100 | + [int] |
| 101 | + $FirstLineHanging, |
| 102 | + |
| 103 | + # Specifies how many characters the first line of data is shifted to the right. This implies -Frame. |
| 104 | + [Parameter(ValueFromPipelineByPropertyName)] |
| 105 | + [ValidateRange(0,1mb)] |
| 106 | + [int] |
| 107 | + $FirstLineIndent, |
| 108 | + |
80 | 109 | # The name of one or more $psStyle properties to apply. |
81 | 110 | # If $psStyle is present, this will use put these properties prior to an expression. |
82 | 111 | # A $psStyle.Reset will be outputted after the expression. |
|
157 | 186 | # With script blocks, the variables $N and $Number will be set to indicate the current iteration. |
158 | 187 | [ValidateRange(1,10kb)] |
159 | 188 | [uint32] |
160 | | - $Count = 1) |
| 189 | + $Count = 1 |
| 190 | + ) |
161 | 191 |
|
162 | 192 | process { |
163 | 193 | # If this is calling itself recursively in ScriptBlock |
@@ -270,6 +300,21 @@ $if") |
270 | 300 | </ExpressionBinding> |
271 | 301 | "@ |
272 | 302 |
|
| 303 | +if ($Frame -or $FirstLineHanging -or $LeftIndent -or $RightIndent -or $FirstLineIndent) { |
| 304 | + $formatExpression = " |
| 305 | +<Frame> |
| 306 | + $( |
| 307 | + if ($LeftIndent) { "<LeftIndent>$LeftIndent</LeftIndent>" } |
| 308 | + if ($RightIndent) { "<RightIndent>$RightIndent</RightIndent>" } |
| 309 | + if ($FirstLineHanging) { "<FirstLineHanging>$FirstLineHanging</FirstLineHanging>" } |
| 310 | + if ($FirstLineIndent) { "<FirstLineIndent>$FirstLineIndent</FirstLineIndent>" } |
| 311 | + ) |
| 312 | + <CustomItem> |
| 313 | + $FormatExpression |
| 314 | + </CustomItem> |
| 315 | +</Frame> |
| 316 | +" |
| 317 | +} |
273 | 318 | $xml = [xml]$formatExpression |
274 | 319 | if (-not $xml) { return } |
275 | 320 | $xOut=[IO.StringWriter]::new() |
|
0 commit comments