internal OrderByPropertyComparer(bool[] ascending, CultureInfo cultureInfo, bool caseSensitive) { _propertyComparers = new ObjectCommandComparer[ascending.Length]; for (int k = 0; k < ascending.Length; k++) { _propertyComparers[k] = new ObjectCommandComparer(ascending[k], cultureInfo, caseSensitive); } }
/// <summary> /// </summary> protected override void ProcessRecord() { bool isUnique = true; if (_lastObject == null) { // always write first object, but return nothing // on "MSH> get-unique" if (AutomationNull.Value == InputObject) { return; } } else if (OnType) { isUnique = (InputObject.InternalTypeNames[0] != _lastObject.InternalTypeNames[0]); } else if (AsString) { string inputString = InputObject.ToString(); if (_lastObjectAsString == null) { _lastObjectAsString = _lastObject.ToString(); } if (string.Equals( inputString, _lastObjectAsString, StringComparison.CurrentCulture)) { isUnique = false; } else { _lastObjectAsString = inputString; } } else // compare as objects { if (_comparer == null) { _comparer = new ObjectCommandComparer( true, // ascending (doesn't matter) CultureInfo.CurrentCulture, true); // case-sensitive } isUnique = (_comparer.Compare(InputObject, _lastObject) != 0); } if (isUnique) { WriteObject(InputObject); _lastObject = InputObject; } }
private void FilteredWriteObject(PSObject obj, List <PSNoteProperty> addedNoteProperties) { Diagnostics.Assert(obj != null, "This command should never write null"); if (!_unique) { if (obj != AutomationNull.Value) { SetPSCustomObject(obj); WriteObject(obj); } return; } //if only unique is mentioned else if ((_unique)) { bool isObjUnique = true; foreach (UniquePSObjectHelper uniqueObj in _uniques) { ObjectCommandComparer comparer = new ObjectCommandComparer(true, CultureInfo.CurrentCulture, true); if ((comparer.Compare(obj.BaseObject, uniqueObj.WrittenObject.BaseObject) == 0) && (uniqueObj.NotePropertyCount == addedNoteProperties.Count)) { bool found = true; foreach (PSNoteProperty note in addedNoteProperties) { PSMemberInfo prop = uniqueObj.WrittenObject.Properties[note.Name]; if (prop == null || comparer.Compare(prop.Value, note.Value) != 0) { found = false; break; } } if (found) { isObjUnique = false; break; } } else { continue; } } if (isObjUnique) { SetPSCustomObject(obj); _uniques.Add(new UniquePSObjectHelper(obj, addedNoteProperties.Count)); } } }
protected override void ProcessRecord() { bool flag = true; if (this._lastObject == null) { if (AutomationNull.Value == this.InputObject) { return; } } else if (this.OnType != 0) { flag = this.InputObject.InternalTypeNames[0] != this._lastObject.InternalTypeNames[0]; } else if (this.AsString != 0) { string strA = this.InputObject.ToString(); if (this._lastObjectAsString == null) { this._lastObjectAsString = this._lastObject.ToString(); } if (string.Compare(strA, this._lastObjectAsString, StringComparison.CurrentCulture) == 0) { flag = false; } else { this._lastObjectAsString = strA; } } else { if (this._comparer == null) { this._comparer = new ObjectCommandComparer(true, CultureInfo.CurrentCulture, true); } flag = 0 != this._comparer.Compare(this.InputObject, this._lastObject); } if (flag) { base.WriteObject(this.InputObject); this._lastObject = this.InputObject; } }
private void FilteredWriteObject(PSObject obj, List <PSNoteProperty> addedNoteProperties) { if (!this.unique) { if (obj != AutomationNull.Value) { this.SetPSCustomObject(obj); base.WriteObject(obj); } } else if (this.unique) { bool flag = true; foreach (UniquePSObjectHelper helper in this.uniques) { ObjectCommandComparer comparer = new ObjectCommandComparer(true, Thread.CurrentThread.CurrentCulture, true); if ((comparer.Compare(obj.BaseObject, helper.WrittenObject.BaseObject) == 0) && (helper.NotePropertyCount == addedNoteProperties.Count)) { bool flag2 = true; foreach (PSNoteProperty property in addedNoteProperties) { PSMemberInfo info = helper.WrittenObject.Properties[property.Name]; if ((info == null) || (comparer.Compare(info.Value, property.Value) != 0)) { flag2 = false; break; } } if (flag2) { flag = false; break; } } } if (flag) { this.SetPSCustomObject(obj); this.uniques.Add(new UniquePSObjectHelper(obj, addedNoteProperties.Count)); } } }
/// <summary> /// /// </summary> protected override void ProcessRecord() { bool isUnique = true; if (null == _lastObject) { // always write first object, but return nothing // on "MSH> get-unique" if (AutomationNull.Value == InputObject) return; } else if (OnType) { isUnique = (InputObject.InternalTypeNames[0] != _lastObject.InternalTypeNames[0]); } else if (AsString) { string inputString = InputObject.ToString(); if (null == _lastObjectAsString) { _lastObjectAsString = _lastObject.ToString(); } if (0 == String.Compare( inputString, _lastObjectAsString, StringComparison.CurrentCulture)) { isUnique = false; } else { _lastObjectAsString = inputString; } } else // compare as objects { if (null == _comparer) { _comparer = new ObjectCommandComparer( true, // ascending (doesn't matter) CultureInfo.CurrentCulture, true); // case-sensitive } isUnique = (0 != _comparer.Compare(InputObject, _lastObject)); } if (isUnique) { WriteObject(InputObject); _lastObject = InputObject; } }