Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities / System / Activities / Validation / ExtensionMethods.cs / 1305376 / ExtensionMethods.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.Activities.Validation { using System.Collections; using System.Collections.Generic; using System.Text; static class ExtensionMethods { public static bool IsNullOrEmpty(this ICollection c) { return (c == null || c.Count == 0); } public static string AsCommaSeparatedValues(this IEnumerablec) { StringBuilder sb = new StringBuilder(); foreach (string s in c) { if (!string.IsNullOrEmpty(s)) { if (sb.Length == 0) { sb.Append(s); } else { sb.Append(", "); sb.Append(s); } } } return sb.ToString(); } public static int BinarySearch (this IList items, T value, IComparer comparer) { return BinarySearch(items, 0, items.Count, value, comparer); } public static void QuickSort (this IList items, IComparer comparer) { QuickSort(items, 0, items.Count - 1, comparer); } static int BinarySearch (IList items, int startIndex, int length, T value, IComparer comparer) { int start = startIndex; int end = (startIndex + length) - 1; while (start <= end) { int mid = start + ((end - start) >> 1); int result = comparer.Compare(items[mid], value); if (result == 0) { return mid; } if (result < 0) { start = mid + 1; } else { end = mid - 1; } } return ~start; } static void QuickSort (IList items, int startIndex, int endIndex, IComparer comparer) { Stack bounds = new Stack (); do { if (bounds.Count != 0) { endIndex = bounds.Pop(); startIndex = bounds.Pop(); } T pivot = items[startIndex]; int pivotIndex = startIndex; for (int i = startIndex + 1; i <= endIndex; i++) { if (comparer.Compare(pivot, items[i]) > 0) { pivotIndex++; if (pivotIndex != i) { items.Swap(pivotIndex, i); } } } if (startIndex != pivotIndex) { items.Swap(startIndex, pivotIndex); } if (pivotIndex + 1 < endIndex) { bounds.Push(pivotIndex + 1); bounds.Push(endIndex); } if (startIndex < pivotIndex - 1) { bounds.Push(startIndex); bounds.Push(pivotIndex - 1); } } while (bounds.Count != 0); } static void Swap (this IList items, int i, int j) { T temp = items[i]; items[i] = items[j]; items[j] = temp; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- HostProtectionPermission.cs
- BaseConfigurationRecord.cs
- FilterEventArgs.cs
- StructuralType.cs
- XmlSchemaComplexContentRestriction.cs
- ToolStripOverflow.cs
- MultipartContentParser.cs
- DataRecordInternal.cs
- RuntimeCompatibilityAttribute.cs
- Color.cs
- SettingsProperty.cs
- HttpRequestCacheValidator.cs
- FileSecurity.cs
- DBBindings.cs
- TagNameToTypeMapper.cs
- DbProviderSpecificTypePropertyAttribute.cs
- BrowserDefinition.cs
- OdbcConnectionString.cs
- StrokeNodeData.cs
- AssemblySettingAttributes.cs
- ChangePasswordAutoFormat.cs
- OletxResourceManager.cs
- QueryGeneratorBase.cs
- Policy.cs
- HandoffBehavior.cs
- XPathMessageContext.cs
- SizeConverter.cs
- LocalizabilityAttribute.cs
- JsonWriter.cs
- WmlPhoneCallAdapter.cs
- IISUnsafeMethods.cs
- TripleDES.cs
- PersistenceProviderElement.cs
- ObfuscationAttribute.cs
- SignatureDescription.cs
- TextViewBase.cs
- BinaryConverter.cs
- CultureSpecificStringDictionary.cs
- GroupBox.cs
- ValidationError.cs
- EmptyEnumerable.cs
- TextEndOfParagraph.cs
- ClosableStream.cs
- ValueHandle.cs
- AxWrapperGen.cs
- ObjectDataSourceDisposingEventArgs.cs
- StreamGeometryContext.cs
- InstallerTypeAttribute.cs
- SQLRoleProvider.cs
- DocumentGridPage.cs
- XmlRootAttribute.cs
- Point3DAnimationBase.cs
- StylusEditingBehavior.cs
- ChannelAcceptor.cs
- ForeignKeyConstraint.cs
- DataKey.cs
- MediaTimeline.cs
- ParentUndoUnit.cs
- XPathNodeHelper.cs
- StreamUpdate.cs
- TextOutput.cs
- Inflater.cs
- WaitHandle.cs
- DefaultSerializationProviderAttribute.cs
- TraceHandlerErrorFormatter.cs
- QilName.cs
- BinaryReader.cs
- UserNameSecurityTokenProvider.cs
- WebPartCatalogAddVerb.cs
- OdbcRowUpdatingEvent.cs
- Color.cs
- XmlComment.cs
- ServiceObjectContainer.cs
- Separator.cs
- FacetValueContainer.cs
- XmlArrayItemAttribute.cs
- XmlObjectSerializerWriteContextComplex.cs
- Trace.cs
- ReadOnlyKeyedCollection.cs
- ProfileParameter.cs
- RegexParser.cs
- HandlerBase.cs
- FileDialog.cs
- WebPartUserCapability.cs
- PrintPreviewControl.cs
- SqlRecordBuffer.cs
- controlskin.cs
- documentsequencetextpointer.cs
- MarkupExtensionReturnTypeAttribute.cs
- Label.cs
- SvcMapFileLoader.cs
- CodeComment.cs
- SystemColors.cs
- TabControl.cs
- AssemblyAttributesGoHere.cs
- EdmScalarPropertyAttribute.cs
- DataSourceXmlSubItemAttribute.cs
- WebPartDescriptionCollection.cs
- SubpageParaClient.cs
- QueueException.cs