private void ProcessExpandParameter(MshParameter p, PSObject inputObject, List <PSNoteProperty> matchedProperties) { List <MshExpressionResult> values = (p.GetEntry("expression") as MshExpression).GetValues(inputObject); if (values.Count == 0) { ErrorRecord errorRecord = new ErrorRecord(PSTraceSource.NewArgumentException("ExpandProperty", this.ResourcesBaseName, "PropertyNotFound", new object[] { this.expand }), "ExpandPropertyNotFound", ErrorCategory.InvalidArgument, inputObject); throw new SelectObjectException(errorRecord); } if (values.Count > 1) { ErrorRecord record2 = new ErrorRecord(PSTraceSource.NewArgumentException("ExpandProperty", this.ResourcesBaseName, "MutlipleExpandProperties", new object[] { this.expand }), "MutlipleExpandProperties", ErrorCategory.InvalidArgument, inputObject); throw new SelectObjectException(record2); } MshExpressionResult result = values[0]; if (result.Exception == null) { IEnumerable enumerable = LanguagePrimitives.GetEnumerable(result.Result); if (enumerable == null) { PSObject obj2 = PSObject.AsPSObject(result.Result); this.FilteredWriteObject(obj2, matchedProperties); } else { foreach (object obj3 in enumerable) { if (obj3 != null) { PSObject obj4 = PSObject.AsPSObject(obj3); foreach (PSNoteProperty property in matchedProperties) { try { if (obj4.Properties[property.Name] != null) { this.WriteAlreadyExistingPropertyError(property.Name, inputObject, "AlreadyExistingUserSpecifiedPropertyExpand"); } else { obj4.Properties.Add(property); } } catch (ExtendedTypeSystemException) { this.WriteAlreadyExistingPropertyError(property.Name, inputObject, "AlreadyExistingUserSpecifiedPropertyExpand"); } } this.FilteredWriteObject(obj4, matchedProperties); } } } } else { ErrorRecord record3 = new ErrorRecord(result.Exception, "PropertyEvaluationExpand", ErrorCategory.InvalidResult, inputObject); throw new SelectObjectException(record3); } }
internal override Object GetValue(PSObject liveObject) { List <MshExpressionResult> resList = _expression.GetValues(liveObject); if (resList.Count == 0) { return(null); } // Only first element is used. MshExpressionResult result = resList[0]; if (result.Exception != null) { return(null); } object objectResult = result.Result; return(objectResult == null ? String.Empty : ColumnInfo.LimitString(objectResult.ToString())); }
internal override object GetValue(PSObject liveObject) { List <MshExpressionResult> values = this.expression.GetValues(liveObject); if (values.Count == 0) { return(null); } MshExpressionResult result = values[0]; if (result.Exception != null) { return(null); } object obj2 = result.Result; if (obj2 != null) { return(Microsoft.PowerShell.Commands.ColumnInfo.LimitString(obj2.ToString())); } return(string.Empty); }
private void ProcessExpandParameter(MshParameter p, PSObject inputObject, List <PSNoteProperty> matchedProperties) { MshExpression ex = p.GetEntry(FormatParameterDefinitionKeys.ExpressionEntryKey) as MshExpression; List <MshExpressionResult> expressionResults = ex.GetValues(inputObject); if (expressionResults.Count == 0) { ErrorRecord errorRecord = new ErrorRecord( PSTraceSource.NewArgumentException("ExpandProperty", SelectObjectStrings.PropertyNotFound, ExpandProperty), "ExpandPropertyNotFound", ErrorCategory.InvalidArgument, inputObject); throw new SelectObjectException(errorRecord); } if (expressionResults.Count > 1) { ErrorRecord errorRecord = new ErrorRecord( PSTraceSource.NewArgumentException("ExpandProperty", SelectObjectStrings.MutlipleExpandProperties, ExpandProperty), "MutlipleExpandProperties", ErrorCategory.InvalidArgument, inputObject); throw new SelectObjectException(errorRecord); } MshExpressionResult r = expressionResults[0]; if (r.Exception == null) { // ignore the property value if it's null if (r.Result == null) { return; } System.Collections.IEnumerable results = LanguagePrimitives.GetEnumerable(r.Result); if (results == null) { // add NoteProperties if there is any // If r.Result is a base object, we don't want to associate the NoteProperty // directly with it. We want the NoteProperty to be associated only with this // particular PSObject, so that when the user uses the base object else where, // its members remain the same as before the Select-Object command run. PSObject expandedObject = PSObject.AsPSObject(r.Result, true); AddNoteProperties(expandedObject, inputObject, matchedProperties); FilteredWriteObject(expandedObject, matchedProperties); return; } foreach (object expandedValue in results) { // ignore the element if it's null if (expandedValue == null) { continue; } // add NoteProperties if there is any // If expandedValue is a base object, we don't want to associate the NoteProperty // directly with it. We want the NoteProperty to be associated only with this // particular PSObject, so that when the user uses the base object else where, // its members remain the same as before the Select-Object command run. PSObject expandedObject = PSObject.AsPSObject(expandedValue, true); AddNoteProperties(expandedObject, inputObject, matchedProperties); FilteredWriteObject(expandedObject, matchedProperties); } } else { ErrorRecord errorRecord = new ErrorRecord( r.Exception, "PropertyEvaluationExpand", ErrorCategory.InvalidResult, inputObject); throw new SelectObjectException(errorRecord); } }