| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1bfe96d commit 87ccd0a
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -191,6 +191,14 @@ internal static IEnumerable<ExtendedTypeDefinition> GetFormatData() | |||
| 191 | 191 | "System.Management.Automation.Job", | |
| 192 | 192 | ViewsOf_System_Management_Automation_Job()); | |
| 193 | 193 | ||
| 194 | + yield return new ExtendedTypeDefinition( | ||
| 195 | + "Microsoft.PowerShell.Commands.TextMeasureInfo", | ||
| 196 | + ViewsOf_Deserialized_Microsoft_PowerShell_Commands_TextMeasureInfo()); | ||
| 197 | + | ||
| 198 | + yield return new ExtendedTypeDefinition( | ||
| 199 | + "Microsoft.PowerShell.Commands.GenericMeasureInfo", | ||
| 200 | + ViewsOf_Deserialized_Microsoft_PowerShell_Commands_GenericMeasureInfo()); | ||
| 201 | + | ||
| 194 | 202 | yield return new ExtendedTypeDefinition( | |
| 195 | 203 | "Deserialized.Microsoft.PowerShell.Commands.TextMeasureInfo", | |
| 196 | 204 | ViewsOf_Deserialized_Microsoft_PowerShell_Commands_TextMeasureInfo()); | |
@@ -1070,11 +1078,11 @@ private static IEnumerable<FormatViewDefinition> ViewsOf_Deserialized_Microsoft_ | |||
| 1070 | 1078 | ListControl.Create() | |
| 1071 | 1079 | .StartEntry() | |
| 1072 | 1080 | .AddItemProperty(@"Count") | |
| 1073 | - .AddItemProperty(@"Average") | ||
| 1074 | - .AddItemProperty(@"Sum") | ||
| 1075 | - .AddItemProperty(@"Maximum") | ||
| 1076 | - .AddItemProperty(@"Minimum") | ||
| 1077 | - .AddItemProperty(@"Property") | ||
| 1081 | + .AddItemPropertyIfSet(@"Average") | ||
| 1082 | + .AddItemPropertyIfSet(@"Sum") | ||
| 1083 | + .AddItemPropertyIfSet(@"Maximum") | ||
| 1084 | + .AddItemPropertyIfSet(@"Minimum") | ||
| 1085 | + .AddItemPropertyIfSet(@"Property") | ||
| 1078 | 1086 | .EndEntry() | |
| 1079 | 1087 | .EndList()); | |
| 1080 | 1088 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -788,7 +788,27 @@ public DisplayEntry(string value, DisplayEntryValueType type) | |||
| 788 | 788 | ValueType = type; | |
| 789 | 789 | } | |
| 790 | 790 | ||
| 791 | - /// <summary/> | ||
| 791 | + /// <summary> | ||
| 792 | + /// Creates a DisplayEntry for the given scriptblock. | ||
| 793 | + /// </summary> | ||
| 794 | + /// <param name="scriptblock">The content of the scriptblock.</param> | ||
| 795 | + /// <returns>A <see cref="DisplayEntry"/> for the <paramref name="scriptblock"/>.</returns> | ||
| 796 | + public static DisplayEntry CreateScriptBlockEntry(string scriptblock) | ||
| 797 | + { | ||
| 798 | + return new DisplayEntry(scriptblock, DisplayEntryValueType.ScriptBlock); | ||
| 799 | + } | ||
| 800 | + | ||
| 801 | + /// <summary> | ||
| 802 | + /// Creates a DisplayEntry for the given property name. | ||
| 803 | + /// </summary> | ||
| 804 | + /// <param name="property">The name of the property.</param> | ||
| 805 | + /// <returns>A <see cref="DisplayEntry"/> for the <paramref name="property"/>.</returns> | ||
| 806 | + public static DisplayEntry CreatePropertyEntry(string property) | ||
| 807 | + { | ||
| 808 | + return new DisplayEntry(property, DisplayEntryValueType.Property); | ||
| 809 | + } | ||
| 810 | + | ||
| 811 | + /// <inheritdoc /> | ||
| 792 | 812 | public override string ToString() | |
| 793 | 813 | { | |
| 794 | 814 | return (ValueType == DisplayEntryValueType.Property ? "property: " : "script: ") + Value; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -370,31 +370,57 @@ internal ListEntryBuilder(ListControlBuilder listBuilder, ListControlEntry listE | |||
| 370 | 370 | _listEntry = listEntry; | |
| 371 | 371 | } | |
| 372 | 372 | ||
| 373 | - private ListEntryBuilder AddItem(string value, string label, DisplayEntryValueType kind, string format) | ||
| 373 | + private ListEntryBuilder AddItem(string value, string label, DisplayEntryValueType kind, string format, DisplayEntry itemSelectionCondition) | ||
| 374 | 374 | { | |
| 375 | 375 | if (string.IsNullOrEmpty(value)) | |
| 376 | + { | ||
| 376 | 377 | throw PSTraceSource.NewArgumentNullException("property"); | |
| 378 | + } | ||
| 377 | 379 | ||
| 378 | 380 | _listEntry.Items.Add(new ListControlEntryItem | |
| 379 | 381 | { | |
| 380 | 382 | DisplayEntry = new DisplayEntry(value, kind), | |
| 381 | 383 | Label = label, | |
| 382 | - FormatString = format | ||
| 384 | + FormatString = format, | ||
| 385 | + ItemSelectionCondition = itemSelectionCondition, | ||
| 383 | 386 | }); | |
| 384 | 387 | ||
| 385 | 388 | return this; | |
| 386 | 389 | } | |
| 387 | 390 | ||
| 388 | - /// <summary></summary> | ||
| 389 | - public ListEntryBuilder AddItemScriptBlock(string scriptBlock, string label = null, string format = null) | ||
| 391 | + /// <summary>Adds a scriptblock list entry.</summary> | ||
| 392 | + /// <param name="scriptBlock">The content of the scriptblock to add.</param> | ||
| 393 | + /// <param name="label">A label for the entry.</param> | ||
| 394 | + /// <param name="format">A format string for the scriptblock result.</param> | ||
| 395 | + /// <param name="itemSelectionCondition">A condition that has to be met for the entry to be displayed.</param> | ||
| 396 | + /// <returns>A reference to this instance after the append operation has completed.</returns> | ||
| 397 | + public ListEntryBuilder AddItemScriptBlock(string scriptBlock, string label = null, string format = null, DisplayEntry itemSelectionCondition = null) | ||
| 390 | 398 | { | |
| 391 | - return AddItem(scriptBlock, label, DisplayEntryValueType.ScriptBlock, format); | ||
| 399 | + return AddItem(scriptBlock, label, DisplayEntryValueType.ScriptBlock, format, itemSelectionCondition); | ||
| 392 | 400 | } | |
| 393 | 401 | ||
| 394 | - /// <summary></summary> | ||
| 395 | - public ListEntryBuilder AddItemProperty(string property, string label = null, string format = null) | ||
| 402 | + /// <summary>Adds a property list entry.</summary> | ||
| 403 | + /// <param name="property">The property to add.</param> | ||
| 404 | + /// <param name="label">A label for the entry.</param> | ||
| 405 | + /// <param name="format">A format string for the property value.</param> | ||
| 406 | + /// <param name="itemSelectionCondition">A condition that has to be met for the entry to be displayed.</param> | ||
| 407 | + /// <returns>A reference to this instance after the append operation has completed.</returns> | ||
| 408 | + public ListEntryBuilder AddItemProperty(string property, string label = null, string format = null, DisplayEntry itemSelectionCondition = null) | ||
| 409 | + { | ||
| 410 | + return AddItem(property, label, DisplayEntryValueType.Property, format, itemSelectionCondition); | ||
| 411 | + } | ||
| 412 | + | ||
| 413 | + /// <summary> | ||
| 414 | + /// Adds a property that is displayed if it the property has a value. | ||
| 415 | + /// </summary> | ||
| 416 | + /// <param name="property">The property to add.</param> | ||
| 417 | + /// <param name="label">A label for the entry.</param> | ||
| 418 | + /// <param name="format">A format string for the property value.</param> | ||
| 419 | + /// <returns>A reference to this instance after the append operation has completed.</returns> | ||
| 420 | + public ListEntryBuilder AddItemPropertyIfSet(string property, string label = null, string format = null) | ||
| 396 | 421 | { | |
| 397 | - return AddItem(property, label, DisplayEntryValueType.Property, format); | ||
| 422 | + var itemSelectionCondition = DisplayEntry.CreatePropertyEntry(property); | ||
| 423 | + return AddItem(property, label, DisplayEntryValueType.Property, format, itemSelectionCondition); | ||
| 398 | 424 | } | |
| 399 | 425 | ||
| 400 | 426 | /// <summary></summary> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -883,6 +883,11 @@ private void LoadListControlItemDefinitionsFromObjectModel(ListControlEntryDefin | |||
| 883 | 883 | fpt.expression = expression; | |
| 884 | 884 | fpt.fieldFormattingDirective.formatString = listItem.FormatString; | |
| 885 | 885 | lvid.formatTokenList.Add(fpt); | |
| 886 | + if (listItem.ItemSelectionCondition != null) | ||
| 887 | + { | ||
| 888 | + var conditionToken = LoadExpressionFromObjectModel(listItem.ItemSelectionCondition, viewIndex, typeName); | ||
| 889 | + lvid.conditionToken = conditionToken; | ||
| 890 | + } | ||
| 886 | 891 | } | |
| 887 | 892 | ||
| 888 | 893 | if (!String.IsNullOrEmpty(listItem.Label)) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,9 +8,9 @@ Describe "Object cmdlets" -Tags "CI" { | |||
| 8 | 8 | } | |
| 9 | 9 | ||
| 10 | 10 | It "AsString returns a string" { | |
| 11 | - $processes = Get-Process | Group-Object -Property ProcessName -AsHashTable -AsString | ||
| 12 | - $result = $processes.Keys | ForEach-Object {$_.GetType()} | ||
| 13 | - $result[0].Name | Should -Be "String" | ||
| 11 | + $processes = Get-Process | Group-Object -Property ProcessName -AsHashTable -AsString | ||
| 12 | + $result = $processes.Keys | ForEach-Object {$_.GetType()} | ||
| 13 | + $result[0].Name | Should -Be "String" | ||
| 14 | 14 | } | |
| 15 | 15 | } | |
| 16 | 16 | ||
@@ -45,18 +45,18 @@ Describe "Object cmdlets" -Tags "CI" { | |||
| 45 | 45 | $secondObject | Add-Member -NotePropertyName Header -NotePropertyValue $secondValue | |
| 46 | 46 | ||
| 47 | 47 | $testCases = @( | |
| 48 | - @{ data = @("abc","ABC","Def"); min = "abc"; max = "Def"}, | ||
| 48 | + @{ data = @("abc", "ABC", "Def"); min = "abc"; max = "Def"}, | ||
| 49 | 49 | @{ data = @([datetime]::Today, [datetime]::Today.AddDays(-1)); min = ([datetime]::Today.AddDays(-1)).ToString() ; max = [datetime]::Today.ToString() } | |
| 50 | - @{ data = @(1,2,3,"ABC"); min = 1; max = "ABC"}, | ||
| 51 | - @{ data = @(4,2,3,"ABC",1); min = 1; max = "ABC"}, | ||
| 52 | - @{ data = @(4,2,3,"ABC",1,"DEF"); min = 1; max = "DEF"}, | ||
| 53 | - @{ data = @("111 Test","19"); min = "111 Test"; max = "19"}, | ||
| 50 | + @{ data = @(1, 2, 3, "ABC"); min = 1; max = "ABC"}, | ||
| 51 | + @{ data = @(4, 2, 3, "ABC", 1); min = 1; max = "ABC"}, | ||
| 52 | + @{ data = @(4, 2, 3, "ABC", 1, "DEF"); min = 1; max = "DEF"}, | ||
| 53 | + @{ data = @("111 Test", "19"); min = "111 Test"; max = "19"}, | ||
| 54 | 54 | @{ data = @("19", "111 Test"); min = "111 Test"; max = "19"}, | |
| 55 | - @{ data = @("111 Test",19); min = "111 Test"; max = 19}, | ||
| 55 | + @{ data = @("111 Test", 19); min = "111 Test"; max = 19}, | ||
| 56 | 56 | @{ data = @(19, "111 Test"); min = "111 Test"; max = 19}, | |
| 57 | - @{ data = @(100,2,3, "A", 1); min = 1; max = "A"}, | ||
| 58 | - @{ data = @(4,2,3, "ABC", 1, "DEF"); min = 1; max = "DEF"}, | ||
| 59 | - @{ data = @("abc",[Datetime]::Today,"def"); min = [Datetime]::Today.ToString(); max = "def"} | ||
| 57 | + @{ data = @(100, 2, 3, "A", 1); min = 1; max = "A"}, | ||
| 58 | + @{ data = @(4, 2, 3, "ABC", 1, "DEF"); min = 1; max = "DEF"}, | ||
| 59 | + @{ data = @("abc", [Datetime]::Today, "def"); min = [Datetime]::Today.ToString(); max = "def"} | ||
| 60 | 60 | ) | |
| 61 | 61 | } | |
| 62 | 62 | ||
@@ -85,18 +85,31 @@ Describe "Object cmdlets" -Tags "CI" { | |||
| 85 | 85 | } | |
| 86 | 86 | ||
| 87 | 87 | It 'returns a GenericMeasureInfoObject' { | |
| 88 | - $gmi = 1,2,3 | measure-object -max -min | ||
| 88 | + $gmi = 1, 2, 3 | measure-object -max -min | ||
| 89 | 89 | $gmi | Should -BeOfType Microsoft.PowerShell.Commands.GenericMeasureInfo | |
| 90 | 90 | } | |
| 91 | 91 | ||
| 92 | 92 | It 'should return correct error for non-numeric input' { | |
| 93 | - $gmi = "abc",[Datetime]::Now | measure -sum -max -ErrorVariable err -ErrorAction silentlycontinue | ||
| 93 | + $gmi = "abc", [Datetime]::Now | measure -sum -max -ErrorVariable err -ErrorAction silentlycontinue | ||
| 94 | 94 | $err | ForEach-Object { $_.FullyQualifiedErrorId | Should -Be 'NonNumericInputObject,Microsoft.PowerShell.Commands.MeasureObjectCommand' } | |
| 95 | 95 | } | |
| 96 | 96 | ||
| 97 | 97 | It 'should have the correct count' { | |
| 98 | - $gmi = "abc",[Datetime]::Now | measure -sum -max -ErrorVariable err -ErrorAction silentlycontinue | ||
| 98 | + $gmi = "abc", [Datetime]::Now | measure -sum -max -ErrorVariable err -ErrorAction silentlycontinue | ||
| 99 | 99 | $gmi.Count | Should -Be 2 | |
| 100 | 100 | } | |
| 101 | + | ||
| 102 | + It 'should only display fields that are set' { | ||
| 103 | + $text = 1, 2, 3 | Measure-Object -Sum -Average | Format-List | Out-String | ||
| 104 | + $text -match "min|max" | Should -BeFalse | ||
| 105 | + $text -match 'Sum' | Should -BeTrue | ||
| 106 | + $text -match 'Average' | Should -BeTrue | ||
| 107 | + | ||
| 108 | + $text = 1, 2, 3 | Measure-Object -Minimum -Maximum | Format-List | Out-String | ||
| 109 | + $text -match "min" | Should -BeTrue | ||
| 110 | + $text -match "max" | Should -BeTrue | ||
| 111 | + $text -match 'Average' | Should -BeFalse | ||
| 112 | + $text -match 'Sum' | Should -BeFalse | ||
| 113 | + } | ||
| 101 | 114 | } | |
| 102 | 115 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments