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; } }