protected override void ProcessRecord() { if (this._inputObject != AutomationNull.Value) { if (this.script != null) { object[] input = new object[] { this._inputObject }; object obj2 = this.script.DoInvokeReturnAsIs(false, ScriptBlock.ErrorHandlingBehavior.WriteToCurrentErrorPipe, this.InputObject, input, AutomationNull.Value, new object[0]); if (this.toBoolSite.Target(this.toBoolSite, obj2)) { base.WriteObject(this.InputObject); } } else { if (this._valueNotSpecified && ((this._binaryOperator != TokenKind.Ieq) || !this._forceBooleanEvaluation)) { base.ThrowTerminatingError(ForEachObjectCommand.GenerateNameParameterError("Value", InternalCommandStrings.ValueNotSpecifiedForWhereObject, "ValueNotSpecifiedForWhereObject", null, new object[0])); } if ((!this._valueNotSpecified && (this._binaryOperator == TokenKind.Ieq)) && this._forceBooleanEvaluation) { base.ThrowTerminatingError(ForEachObjectCommand.GenerateNameParameterError("Operator", InternalCommandStrings.OperatorNotSpecified, "OperatorNotSpecified", null, new object[0])); } bool error = false; object obj3 = this.GetValue(ref error); if (!error) { try { if ((this._binaryOperator == TokenKind.Is) || (this._binaryOperator == TokenKind.IsNot)) { string str = this._value as string; if (((str != null) && str.StartsWith("[", StringComparison.CurrentCulture)) && str.EndsWith("]", StringComparison.CurrentCulture)) { this._value = str.Substring(1, str.Length - 2); } } object obj4 = this.operationDelegate(obj3, this._value); if (this.toBoolSite.Target(this.toBoolSite, obj4)) { base.WriteObject(this.InputObject); } } catch (PipelineStoppedException) { throw; } catch (ArgumentException exception) { ErrorRecord errorRecord = new ErrorRecord(PSTraceSource.NewArgumentException("BinaryOperator", "ParserStrings", "BadOperatorArgument", new object[] { this._binaryOperator, exception.Message }), "BadOperatorArgument", ErrorCategory.InvalidArgument, this._inputObject); base.WriteError(errorRecord); } catch (Exception exception2) { CommandProcessorBase.CheckForSevereException(exception2); ErrorRecord record2 = new ErrorRecord(PSTraceSource.NewInvalidOperationException("ParserStrings", "OperatorFailed", new object[] { this._binaryOperator, exception2.Message }), "OperatorFailed", ErrorCategory.InvalidOperation, this._inputObject); base.WriteError(record2); } } } } }
private object GetValue(ref bool error) { if (LanguagePrimitives.IsNull(this.InputObject)) { if (base.Context.IsStrictVersion(2)) { base.WriteError(ForEachObjectCommand.GenerateNameParameterError("InputObject", InternalCommandStrings.InputObjectIsNull, "InputObjectIsNull", this._inputObject, new object[] { this._property })); error = true; } return(null); } IDictionary dictionary = PSObject.Base(this._inputObject) as IDictionary; try { if ((dictionary != null) && dictionary.Contains(this._property)) { return(dictionary[this._property]); } } catch (InvalidOperationException) { } ReadOnlyPSMemberInfoCollection <PSMemberInfo> matchMembers = this.GetMatchMembers(); if (matchMembers.Count > 1) { StringBuilder builder = new StringBuilder(); foreach (PSMemberInfo info in matchMembers) { builder.AppendFormat(CultureInfo.InvariantCulture, " {0}", new object[] { info.Name }); } base.WriteError(ForEachObjectCommand.GenerateNameParameterError("Property", InternalCommandStrings.AmbiguousPropertyOrMethodName, "AmbiguousPropertyName", this._inputObject, new object[] { this._property, builder })); error = true; } else if (matchMembers.Count == 0) { if (base.Context.IsStrictVersion(2)) { base.WriteError(ForEachObjectCommand.GenerateNameParameterError("Property", InternalCommandStrings.PropertyNotFound, "PropertyNotFound", this._inputObject, new object[] { this._property })); error = true; } } else { try { return(matchMembers[0].Value); } catch (TerminateException) { throw; } catch (MethodException) { throw; } catch (Exception exception) { CommandProcessorBase.CheckForSevereException(exception); return(null); } } return(null); }