GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix for #6855 - Measure-Object should handle scriptblock properties. by BrucePay · Pull Request #6934 · PowerShell/PowerShell

Fix for #6855 - Measure-Object should handle scriptblock properties. #6934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Dongbo Wang (daxian-dbw) merged 7 commits into PowerShell:master from BrucePay:brucepay_MeasureObject
Jun 20, 2018

Uh oh!

There was an error while loading. Please reload this page.

Merged

Fix for #6855 - Measure-Object should handle scriptblock properties. #6934

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
7 commits
Select commit Hold shift + click to select a range
78e9618
merge conflict
Jun 15, 2018
5c94dc3
Added missing type accelerator test, cleaned up tests
Jun 1, 2018
0b0f423
Fix for #6855 - Measure-Object should handle scriptblock properties. …
May 25, 2018
662406e
modified IfHashtableWrapAsPSCustomObject function to use C# 7 pattern…
Jun 1, 2018
0a9525c
Moved PSPropertyExpression shortcut to type accelerator list.
Jun 15, 2018
a7386a9
merge conflict
Jun 16, 2018
999a31c
[Feature] Dummy commit to trigger daily test run
daxian-dbw Jun 19, 2018
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

2 changes: 1 addition & 1 deletion 2 src/Microsoft.PowerShell.Commands.Utility/commands/utility/ConvertFrom-StringData.cs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public sealed class ConvertFromStringDataCommand : PSCmdlet

/// <summary>
/// The list of properties to display
/// These take the form of an MshExpression
/// These take the form of an PSPropertyExpression
/// </summary>
/// <value></value>
[Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true)]
Expand Down
10 changes: 5 additions & 5 deletions 10 ...ell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/ExpressionColumnInfo.cs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ namespace Microsoft.PowerShell.Commands

internal class ExpressionColumnInfo : ColumnInfo
{
private MshExpression _expression;
private PSPropertyExpression _expression;

internal ExpressionColumnInfo(string staleObjectPropertyName, string displayName, MshExpression expression)
internal ExpressionColumnInfo(string staleObjectPropertyName, string displayName, PSPropertyExpression expression)
: base(staleObjectPropertyName, displayName)
{
_expression = expression;
}

internal override Object GetValue(PSObject liveObject)
{
List<MshExpressionResult> resList = _expression.GetValues(liveObject);
List<PSPropertyExpressionResult> resList = _expression.GetValues(liveObject);

if (resList.Count == 0)
{
return null;
}

// Only first element is used.
MshExpressionResult result = resList[0];
PSPropertyExpressionResult result = resList[0];
if (result.Exception != null)
{
return null;
Expand All @@ -38,4 +38,4 @@ internal override Object GetValue(PSObject liveObject)
return objectResult == null ? String.Empty : ColumnInfo.LimitString(objectResult.ToString());
}
}
}
}
4 changes: 2 additions & 2 deletions 4 ...Shell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/OutGridViewCommand.cs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class OutGridViewCommand : PSCmdlet, IDisposable
private const string DataNotQualifiedForGridView = "DataNotQualifiedForGridView";
private const string RemotingNotSupported = "RemotingNotSupported";
private TypeInfoDataBase _typeInfoDataBase;
private MshExpressionFactory _expressionFactory;
private PSPropertyExpressionFactory _expressionFactory;
private OutWindowProxy _windowProxy;
private GridHeader _gridHeader;

Expand Down Expand Up @@ -110,7 +110,7 @@ public SwitchParameter PassThru
protected override void BeginProcessing()
{
// Set up the ExpressionFactory
_expressionFactory = new MshExpressionFactory();
_expressionFactory = new PSPropertyExpressionFactory();

// If the value of the Title parameter is valid, use it as a window's title.
if (this.Title != null)
Expand Down
8 changes: 4 additions & 4 deletions 8 ...oft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/OutGridView/TableView.cs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ namespace Microsoft.PowerShell.Commands

internal class TableView
{
private MshExpressionFactory _expressionFactory;
private PSPropertyExpressionFactory _expressionFactory;
private TypeInfoDataBase _typeInfoDatabase;
private FormatErrorManager _errorManager;

internal void Initialize(MshExpressionFactory expressionFactory,
internal void Initialize(PSPropertyExpressionFactory expressionFactory,
TypeInfoDataBase db)
{
_expressionFactory = expressionFactory;
Expand Down Expand Up @@ -78,7 +78,7 @@ internal HeaderInfo GenerateHeaderInfo(PSObject input, TableControlBody tableBod
}
if (fpt.expression.isScriptBlock)
{
MshExpression ex = _expressionFactory.CreateFromExpressionToken(fpt.expression);
PSPropertyExpression ex = _expressionFactory.CreateFromExpressionToken(fpt.expression);
// Using the displayName as a propertyName for a stale PSObject.
const string LastWriteTimePropertyName = "LastWriteTime";

Expand Down Expand Up @@ -132,7 +132,7 @@ internal HeaderInfo GenerateHeaderInfo(PSObject input, OutGridViewCommand parent
if (PSObjectHelper.ShouldShowComputerNameProperty(input))
{
activeAssociationList.Add(new MshResolvedExpressionParameterAssociation(null,
new MshExpression(RemotingConstants.ComputerNameNoteProperty)));
new PSPropertyExpression(RemotingConstants.ComputerNameNoteProperty)));
}
}
else
Expand Down
16 changes: 7 additions & 9 deletions 16 src/Microsoft.PowerShell.Commands.Utility/commands/utility/Measure-Object.cs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ public GenericMeasureInfo()
/// Class output by Measure-Object.
/// </summary>
/// <remarks>
/// This class is created for fixing "Measure-Object -MAX -MIN should work with ANYTHING that supports CompareTo"
/// bug (Win8:343911).
/// This class is created to make 'Measure-Object -MAX -MIN' work with ANYTHING that supports 'CompareTo'.
/// GenericMeasureInfo class is shipped with PowerShell V2. Fixing this bug requires, changing the type of
/// Maximum and Minimum properties which would be a breaking change. Hence created a new class to not
/// have an appcompat issues with PS V2.
Expand Down Expand Up @@ -271,7 +270,7 @@ public MeasureObjectCommand()
/// <value></value>
[ValidateNotNullOrEmpty]
[Parameter(Position = 0)]
public string[] Property { get; set; } = null;
public PSPropertyExpression[] Property { get; set; } = null;

#endregion Common parameters in both sets

Expand Down Expand Up @@ -486,10 +485,9 @@ private void AnalyzeObjectProperties(PSObject inObj)

// First iterate over the user-specified list of
// properties...
foreach (string p in Property)
foreach (var expression in Property)
{
MshExpression expression = new MshExpression(p);
List<MshExpression> resolvedNames = expression.ResolveNames(inObj);
List<PSPropertyExpression> resolvedNames = expression.ResolveNames(inObj);
if (resolvedNames == null || resolvedNames.Count == 0)
{
// Insert a blank entry so we can track
Expand All @@ -506,7 +504,7 @@ private void AnalyzeObjectProperties(PSObject inObj)
// Each property value can potentially refer
// to multiple properties via globbing. Iterate over
// the actual property names.
foreach (MshExpression resolvedName in resolvedNames)
foreach (PSPropertyExpression resolvedName in resolvedNames)
{
string propertyName = resolvedName.ToString();
// skip duplicated properties
Expand All @@ -515,7 +513,7 @@ private void AnalyzeObjectProperties(PSObject inObj)
continue;
}

List<MshExpressionResult> tempExprRes = resolvedName.GetValues(inObj);
List<PSPropertyExpressionResult> tempExprRes = resolvedName.GetValues(inObj);
if (tempExprRes == null || tempExprRes.Count == 0)
{
// Shouldn't happen - would somehow mean
Expand Down Expand Up @@ -573,7 +571,7 @@ private void AnalyzeValue(string propertyName, object objValue)
AnalyzeNumber(numValue, stat);
}

// Win8:343911 Measure-Object -MAX -MIN should work with ANYTHING that supports CompareTo
// Measure-Object -MAX -MIN should work with ANYTHING that supports CompareTo
if (_measureMin)
{
stat.min = Compare(objValue, stat.min, true);
Expand Down
28 changes: 14 additions & 14 deletions 28 src/Microsoft.PowerShell.Commands.Utility/commands/utility/OrderObjectBase.cs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ internal List<MshParameter> MshParameterList
// a string array and allows wildcard.
// Yes, the Cmdlet is needed. It's used to get the TerminatingErrorContext, WriteError and WriteDebug.

#region process MshExpression and MshParameter
#region process PSPropertyExpression and MshParameter

private static void ProcessExpressionParameter(
List<PSObject> inputObjects,
Expand Down Expand Up @@ -245,7 +245,7 @@ internal void ProcessExpressionParameter(

foreach (MshParameter unexpandedParameter in _unexpandedParameterList)
{
MshExpression mshExpression = (MshExpression)unexpandedParameter.GetEntry(FormatParameterDefinitionKeys.ExpressionEntryKey);
PSPropertyExpression mshExpression = (PSPropertyExpression)unexpandedParameter.GetEntry(FormatParameterDefinitionKeys.ExpressionEntryKey);
if (!mshExpression.HasWildCardCharacters) // this special cases 1) script blocks and 2) wildcard-less strings
{
_mshParameterList.Add(unexpandedParameter);
Expand Down Expand Up @@ -274,14 +274,14 @@ private static List<MshParameter> ExpandExpressions(List<PSObject> inputObjects,
{
foreach (MshParameter unexpandedParameter in unexpandedParameterList)
{
MshExpression ex = (MshExpression)unexpandedParameter.GetEntry(FormatParameterDefinitionKeys.ExpressionEntryKey);
PSPropertyExpression ex = (PSPropertyExpression)unexpandedParameter.GetEntry(FormatParameterDefinitionKeys.ExpressionEntryKey);
if (!ex.HasWildCardCharacters) // this special cases 1) script blocks and 2) wildcard-less strings
{
expandedParameterList.Add(unexpandedParameter);
}
else
{
SortedDictionary<string, MshExpression> expandedPropertyNames = new SortedDictionary<string, MshExpression>(StringComparer.OrdinalIgnoreCase);
SortedDictionary<string, PSPropertyExpression> expandedPropertyNames = new SortedDictionary<string, PSPropertyExpression>(StringComparer.OrdinalIgnoreCase);
if (inputObjects != null)
{
foreach (object inputObject in inputObjects)
Expand All @@ -291,14 +291,14 @@ private static List<MshParameter> ExpandExpressions(List<PSObject> inputObjects,
continue;
}

foreach (MshExpression resolvedName in ex.ResolveNames(PSObject.AsPSObject(inputObject)))
foreach (PSPropertyExpression resolvedName in ex.ResolveNames(PSObject.AsPSObject(inputObject)))
{
expandedPropertyNames[resolvedName.ToString()] = resolvedName;
}
}
}

foreach (MshExpression expandedExpression in expandedPropertyNames.Values)
foreach (PSPropertyExpression expandedExpression in expandedPropertyNames.Values)
{
MshParameter expandedParameter = new MshParameter();
expandedParameter.hash = (Hashtable)unexpandedParameter.hash.Clone();
Expand All @@ -321,20 +321,20 @@ private static void ExpandExpressions(PSObject inputObject, List<MshParameter> U
{
foreach (MshParameter unexpandedParameter in UnexpandedParametersWithWildCardPattern)
{
MshExpression ex = (MshExpression)unexpandedParameter.GetEntry(FormatParameterDefinitionKeys.ExpressionEntryKey);
PSPropertyExpression ex = (PSPropertyExpression)unexpandedParameter.GetEntry(FormatParameterDefinitionKeys.ExpressionEntryKey);

SortedDictionary<string, MshExpression> expandedPropertyNames = new SortedDictionary<string, MshExpression>(StringComparer.OrdinalIgnoreCase);
SortedDictionary<string, PSPropertyExpression> expandedPropertyNames = new SortedDictionary<string, PSPropertyExpression>(StringComparer.OrdinalIgnoreCase);
if (inputObject == null)
{
continue;
}

foreach (MshExpression resolvedName in ex.ResolveNames(PSObject.AsPSObject(inputObject)))
foreach (PSPropertyExpression resolvedName in ex.ResolveNames(PSObject.AsPSObject(inputObject)))
{
expandedPropertyNames[resolvedName.ToString()] = resolvedName;
}

foreach (MshExpression expandedExpression in expandedPropertyNames.Values)
foreach (PSPropertyExpression expandedExpression in expandedPropertyNames.Values)
{
MshParameter expandedParameter = new MshParameter();
expandedParameter.hash = (Hashtable)unexpandedParameter.hash.Clone();
Expand Down Expand Up @@ -364,7 +364,7 @@ internal static string[] GetDefaultKeyPropertySet(PSObject mshObj)
return props;
}

#endregion process MshExpression and MshParameter
#endregion process PSPropertyExpression and MshParameter

internal static List<OrderByPropertyEntry> CreateOrderMatrix(
PSCmdlet cmdlet,
Expand Down Expand Up @@ -569,10 +569,10 @@ private static void EvaluateSortingExpression(
ref bool comparable)
{
// NOTE: we assume globbing was not allowed in input
MshExpression ex = p.GetEntry(FormatParameterDefinitionKeys.ExpressionEntryKey) as MshExpression;
PSPropertyExpression ex = p.GetEntry(FormatParameterDefinitionKeys.ExpressionEntryKey) as PSPropertyExpression;

// get the values, but do not expand aliases
List<MshExpressionResult> expressionResults = ex.GetValues(inputObject, false, true);
List<PSPropertyExpressionResult> expressionResults = ex.GetValues(inputObject, false, true);

if (expressionResults.Count == 0)
{
Expand All @@ -584,7 +584,7 @@ private static void EvaluateSortingExpression(
}
propertyNotFoundMsg = null;
// we obtained some results, enter them into the list
foreach (MshExpressionResult r in expressionResults)
foreach (PSPropertyExpressionResult r in expressionResults)
{
if (r.Exception == null)
{
Expand Down
16 changes: 8 additions & 8 deletions 16 src/Microsoft.PowerShell.Commands.Utility/commands/utility/convert-HTML.cs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public PSObject InputObject

/// <summary>
/// The list of properties to display
/// These take the form of an MshExpression
/// These take the form of a PSPropertyExpression
/// </summary>
/// <value></value>
[Parameter(Position = 0)]
Expand Down Expand Up @@ -342,9 +342,9 @@ private void InitializeResolvedNameMshParameters()
string label = p.GetEntry(ConvertHTMLParameterDefinitionKeys.LabelEntryKey) as string;
string alignment = p.GetEntry(ConvertHTMLParameterDefinitionKeys.AlignmentEntryKey) as string;
string width = p.GetEntry(ConvertHTMLParameterDefinitionKeys.WidthEntryKey) as string;
MshExpression ex = p.GetEntry(FormatParameterDefinitionKeys.ExpressionEntryKey) as MshExpression;
List<MshExpression> resolvedNames = ex.ResolveNames(_inputObject);
foreach (MshExpression resolvedName in resolvedNames)
PSPropertyExpression ex = p.GetEntry(FormatParameterDefinitionKeys.ExpressionEntryKey) as PSPropertyExpression;
List<PSPropertyExpression> resolvedNames = ex.ResolveNames(_inputObject);
foreach (PSPropertyExpression resolvedName in resolvedNames)
{
Hashtable ht = CreateAuxPropertyHT(label, alignment, width);
ht.Add(FormatParameterDefinitionKeys.ExpressionEntryKey, resolvedName.ToString());
Expand Down Expand Up @@ -567,7 +567,7 @@ private void WritePropertyName(StringBuilder Listtag, MshParameter p)
}
else
{
MshExpression ex = p.GetEntry(FormatParameterDefinitionKeys.ExpressionEntryKey) as MshExpression;
PSPropertyExpression ex = p.GetEntry(FormatParameterDefinitionKeys.ExpressionEntryKey) as PSPropertyExpression;
Listtag.Append(ex.ToString());
}
}
Expand All @@ -577,11 +577,11 @@ private void WritePropertyName(StringBuilder Listtag, MshParameter p)
/// </summary>
private void WritePropertyValue(StringBuilder Listtag, MshParameter p)
{
MshExpression exValue = p.GetEntry(FormatParameterDefinitionKeys.ExpressionEntryKey) as MshExpression;
PSPropertyExpression exValue = p.GetEntry(FormatParameterDefinitionKeys.ExpressionEntryKey) as PSPropertyExpression;

// get the value of the property
List<MshExpressionResult> resultList = exValue.GetValues(_inputObject);
foreach (MshExpressionResult result in resultList)
List<PSPropertyExpressionResult> resultList = exValue.GetValues(_inputObject);
foreach (PSPropertyExpressionResult result in resultList)
{
// create comma sep list for multiple results
if (result.Result != null)
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.