Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / ndp / fx / src / DataSet / System / Data / EnumerableRowCollectionExtensions.cs / 1 / EnumerableRowCollectionExtensions.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //[....] //----------------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Globalization; using System.Diagnostics; namespace System.Data { ////// This static class defines the extension methods that add LINQ operator functionality /// within IEnumerableDT and IOrderedEnumerableDT. /// public static class EnumerableRowCollectionExtensions { ////// LINQ's Where operator for generic EnumerableRowCollection. /// public static EnumerableRowCollectionWhere ( this EnumerableRowCollection source, Func predicate) { EnumerableRowCollection edt = new EnumerableRowCollection (source, Enumerable.Where (source, predicate), null); //copy constructor edt.AddPredicate(predicate); return edt; } /// /// LINQ's OrderBy operator for generic EnumerableRowCollection. /// public static OrderedEnumerableRowCollectionOrderBy ( this EnumerableRowCollection source, Func keySelector) { IEnumerable ie = Enumerable.OrderBy (source, keySelector); OrderedEnumerableRowCollection edt = new OrderedEnumerableRowCollection (source, ie); edt.AddSortExpression(keySelector, false, true); return edt; } /// /// LINQ's OrderBy operator for generic EnumerableRowCollection. /// public static OrderedEnumerableRowCollectionOrderBy ( this EnumerableRowCollection source, Func keySelector, IComparer comparer) { IEnumerable ie = Enumerable.OrderBy (source, keySelector, comparer); OrderedEnumerableRowCollection edt = new OrderedEnumerableRowCollection (source, ie); edt.AddSortExpression(keySelector, comparer, false, true); return edt; } /// /// LINQ's OrderByDescending operator for generic EnumerableRowCollection. /// public static OrderedEnumerableRowCollectionOrderByDescending ( this EnumerableRowCollection source, Func keySelector) { IEnumerable ie = Enumerable.OrderByDescending (source, keySelector); OrderedEnumerableRowCollection edt = new OrderedEnumerableRowCollection (source, ie); edt.AddSortExpression(keySelector, true, true); return edt; } /// /// LINQ's OrderByDescending operator for generic EnumerableRowCollection. /// public static OrderedEnumerableRowCollectionOrderByDescending ( this EnumerableRowCollection source, Func keySelector, IComparer comparer) { IEnumerable ie = Enumerable.OrderByDescending (source, keySelector, comparer); OrderedEnumerableRowCollection edt = new OrderedEnumerableRowCollection (source, ie); edt.AddSortExpression(keySelector, comparer, true, true); return edt; } /// /// LINQ's ThenBy operator for generic EnumerableRowCollection. /// public static OrderedEnumerableRowCollectionThenBy ( this OrderedEnumerableRowCollection source, Func keySelector) { IEnumerable ie = Enumerable.ThenBy ((IOrderedEnumerable )source.EnumerableRows, keySelector); OrderedEnumerableRowCollection edt = new OrderedEnumerableRowCollection ((EnumerableRowCollection )source, ie); edt.AddSortExpression(keySelector, /*isDesc*/ false, /*isOrderBy*/ false); return edt; } /// /// LINQ's ThenBy operator for generic EnumerableRowCollection. /// public static OrderedEnumerableRowCollectionThenBy ( this OrderedEnumerableRowCollection source, Func keySelector, IComparer comparer) { IEnumerable ie = Enumerable.ThenBy ((IOrderedEnumerable )source.EnumerableRows, keySelector, comparer); OrderedEnumerableRowCollection edt = new OrderedEnumerableRowCollection ((EnumerableRowCollection )source, ie); edt.AddSortExpression(keySelector, comparer, false, false); return edt; } /// /// LINQ's ThenByDescending operator for generic EnumerableRowCollection. /// public static OrderedEnumerableRowCollectionThenByDescending ( this OrderedEnumerableRowCollection source, Func keySelector) { IEnumerable ie = Enumerable.ThenByDescending ((IOrderedEnumerable )source.EnumerableRows, keySelector); OrderedEnumerableRowCollection edt = new OrderedEnumerableRowCollection ((EnumerableRowCollection )source, ie); edt.AddSortExpression(keySelector, /*desc*/ true, false); return edt; } /// /// LINQ's ThenByDescending operator for generic EnumerableRowCollection. /// public static OrderedEnumerableRowCollectionThenByDescending ( this OrderedEnumerableRowCollection source, Func keySelector, IComparer comparer) { IEnumerable ie = Enumerable.ThenByDescending ((IOrderedEnumerable )source.EnumerableRows, keySelector, comparer); OrderedEnumerableRowCollection edt = new OrderedEnumerableRowCollection ((EnumerableRowCollection )source, ie); edt.AddSortExpression(keySelector, comparer, true, false); return edt; } /// /// Executes a Select (Projection) on EnumerableDataTable. If the selector returns a different /// type than the type of rows, then AsLinqDataView is disabled, and the returning EnumerableDataTable /// represents an enumerable over the LINQ Query. /// public static EnumerableRowCollectionSelect( this EnumerableRowCollection source, Func selector) { //Anonymous type or some other type //The only thing that matters from this point on is _enumerableRows IEnumerable typedEnumerable = Enumerable.Select(source, selector); // Dont need predicates or sort expression from this point on since we know // AsLinqDataView is disabled. return new EnumerableRowCollection (((object)source) as EnumerableRowCollection, typedEnumerable, ((object)selector) as Func); } ////// Casts an EnumerableDataTable_TSource into EnumerableDataTable_TResult /// public static EnumerableRowCollectionCast (this EnumerableRowCollection source) { // Since Cast does not have the signature Cast_T_R(..) this call is routed // through the non-generic base class EnumerableDataTable if ((null != source) && source.ElementType.Equals(typeof(TResult))) { return (EnumerableRowCollection )(object)source; } else { //Anonymous type or some other type //The only thing that matters from this point on is _enumerableRows IEnumerable typedEnumerable = Enumerable.Cast (source); EnumerableRowCollection newEdt = new EnumerableRowCollection ( typedEnumerable, typeof(TResult).IsAssignableFrom(source.ElementType) && typeof(DataRow).IsAssignableFrom(typeof(TResult)), source.Table); return newEdt; } } } //end class } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //[....] //----------------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Globalization; using System.Diagnostics; namespace System.Data { ////// This static class defines the extension methods that add LINQ operator functionality /// within IEnumerableDT and IOrderedEnumerableDT. /// public static class EnumerableRowCollectionExtensions { ////// LINQ's Where operator for generic EnumerableRowCollection. /// public static EnumerableRowCollectionWhere ( this EnumerableRowCollection source, Func predicate) { EnumerableRowCollection edt = new EnumerableRowCollection (source, Enumerable.Where (source, predicate), null); //copy constructor edt.AddPredicate(predicate); return edt; } /// /// LINQ's OrderBy operator for generic EnumerableRowCollection. /// public static OrderedEnumerableRowCollectionOrderBy ( this EnumerableRowCollection source, Func keySelector) { IEnumerable ie = Enumerable.OrderBy (source, keySelector); OrderedEnumerableRowCollection edt = new OrderedEnumerableRowCollection (source, ie); edt.AddSortExpression(keySelector, false, true); return edt; } /// /// LINQ's OrderBy operator for generic EnumerableRowCollection. /// public static OrderedEnumerableRowCollectionOrderBy ( this EnumerableRowCollection source, Func keySelector, IComparer comparer) { IEnumerable ie = Enumerable.OrderBy (source, keySelector, comparer); OrderedEnumerableRowCollection edt = new OrderedEnumerableRowCollection (source, ie); edt.AddSortExpression(keySelector, comparer, false, true); return edt; } /// /// LINQ's OrderByDescending operator for generic EnumerableRowCollection. /// public static OrderedEnumerableRowCollectionOrderByDescending ( this EnumerableRowCollection source, Func keySelector) { IEnumerable ie = Enumerable.OrderByDescending (source, keySelector); OrderedEnumerableRowCollection edt = new OrderedEnumerableRowCollection (source, ie); edt.AddSortExpression(keySelector, true, true); return edt; } /// /// LINQ's OrderByDescending operator for generic EnumerableRowCollection. /// public static OrderedEnumerableRowCollectionOrderByDescending ( this EnumerableRowCollection source, Func keySelector, IComparer comparer) { IEnumerable ie = Enumerable.OrderByDescending (source, keySelector, comparer); OrderedEnumerableRowCollection edt = new OrderedEnumerableRowCollection (source, ie); edt.AddSortExpression(keySelector, comparer, true, true); return edt; } /// /// LINQ's ThenBy operator for generic EnumerableRowCollection. /// public static OrderedEnumerableRowCollectionThenBy ( this OrderedEnumerableRowCollection source, Func keySelector) { IEnumerable ie = Enumerable.ThenBy ((IOrderedEnumerable )source.EnumerableRows, keySelector); OrderedEnumerableRowCollection edt = new OrderedEnumerableRowCollection ((EnumerableRowCollection )source, ie); edt.AddSortExpression(keySelector, /*isDesc*/ false, /*isOrderBy*/ false); return edt; } /// /// LINQ's ThenBy operator for generic EnumerableRowCollection. /// public static OrderedEnumerableRowCollectionThenBy ( this OrderedEnumerableRowCollection source, Func keySelector, IComparer comparer) { IEnumerable ie = Enumerable.ThenBy ((IOrderedEnumerable )source.EnumerableRows, keySelector, comparer); OrderedEnumerableRowCollection edt = new OrderedEnumerableRowCollection ((EnumerableRowCollection )source, ie); edt.AddSortExpression(keySelector, comparer, false, false); return edt; } /// /// LINQ's ThenByDescending operator for generic EnumerableRowCollection. /// public static OrderedEnumerableRowCollectionThenByDescending ( this OrderedEnumerableRowCollection source, Func keySelector) { IEnumerable ie = Enumerable.ThenByDescending ((IOrderedEnumerable )source.EnumerableRows, keySelector); OrderedEnumerableRowCollection edt = new OrderedEnumerableRowCollection ((EnumerableRowCollection )source, ie); edt.AddSortExpression(keySelector, /*desc*/ true, false); return edt; } /// /// LINQ's ThenByDescending operator for generic EnumerableRowCollection. /// public static OrderedEnumerableRowCollectionThenByDescending ( this OrderedEnumerableRowCollection source, Func keySelector, IComparer comparer) { IEnumerable ie = Enumerable.ThenByDescending ((IOrderedEnumerable )source.EnumerableRows, keySelector, comparer); OrderedEnumerableRowCollection edt = new OrderedEnumerableRowCollection ((EnumerableRowCollection )source, ie); edt.AddSortExpression(keySelector, comparer, true, false); return edt; } /// /// Executes a Select (Projection) on EnumerableDataTable. If the selector returns a different /// type than the type of rows, then AsLinqDataView is disabled, and the returning EnumerableDataTable /// represents an enumerable over the LINQ Query. /// public static EnumerableRowCollectionSelect( this EnumerableRowCollection source, Func selector) { //Anonymous type or some other type //The only thing that matters from this point on is _enumerableRows IEnumerable typedEnumerable = Enumerable.Select(source, selector); // Dont need predicates or sort expression from this point on since we know // AsLinqDataView is disabled. return new EnumerableRowCollection (((object)source) as EnumerableRowCollection, typedEnumerable, ((object)selector) as Func); } ////// Casts an EnumerableDataTable_TSource into EnumerableDataTable_TResult /// public static EnumerableRowCollectionCast (this EnumerableRowCollection source) { // Since Cast does not have the signature Cast_T_R(..) this call is routed // through the non-generic base class EnumerableDataTable if ((null != source) && source.ElementType.Equals(typeof(TResult))) { return (EnumerableRowCollection )(object)source; } else { //Anonymous type or some other type //The only thing that matters from this point on is _enumerableRows IEnumerable typedEnumerable = Enumerable.Cast (source); EnumerableRowCollection newEdt = new EnumerableRowCollection ( typedEnumerable, typeof(TResult).IsAssignableFrom(source.ElementType) && typeof(DataRow).IsAssignableFrom(typeof(TResult)), source.Table); return newEdt; } } } //end class } // 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
- TextRange.cs
- Directory.cs
- BaseEntityWrapper.cs
- UnsafeNativeMethodsPenimc.cs
- ParagraphVisual.cs
- XmlSchemaCollection.cs
- MultiPropertyDescriptorGridEntry.cs
- Simplifier.cs
- ProfessionalColors.cs
- XmlSchemaAnnotation.cs
- ConvertEvent.cs
- HwndStylusInputProvider.cs
- DelegateBodyWriter.cs
- NestPullup.cs
- UnsafeMethods.cs
- StreamReader.cs
- MethodExpr.cs
- SymbolTable.cs
- ClientTargetCollection.cs
- ReflectPropertyDescriptor.cs
- HtmlLinkAdapter.cs
- Int16AnimationUsingKeyFrames.cs
- SR.cs
- NumericExpr.cs
- DesignerDataConnection.cs
- HttpResponseHeader.cs
- Label.cs
- ContextMenuService.cs
- QueryOutputWriter.cs
- _WebProxyDataBuilder.cs
- XmlSchemaType.cs
- COSERVERINFO.cs
- ButtonBaseAutomationPeer.cs
- XslException.cs
- SmiSettersStream.cs
- ColorAnimation.cs
- ActivityWithResultValueSerializer.cs
- PathTooLongException.cs
- StagingAreaInputItem.cs
- TextEditorThreadLocalStore.cs
- EntryPointNotFoundException.cs
- EventHandlersDesigner.cs
- UrlAuthFailedErrorFormatter.cs
- WebPartDisplayModeCollection.cs
- Mappings.cs
- HMACSHA384.cs
- SourceFileInfo.cs
- EventProviderWriter.cs
- Line.cs
- CodeCommentStatementCollection.cs
- GroupBox.cs
- TableSectionStyle.cs
- ColumnResizeUndoUnit.cs
- Code.cs
- InstanceData.cs
- RichListBox.cs
- DataGridCellsPresenter.cs
- DataObjectSettingDataEventArgs.cs
- SymDocumentType.cs
- XmlImplementation.cs
- EdmSchemaAttribute.cs
- SqlTriggerContext.cs
- SoapFault.cs
- COM2PropertyDescriptor.cs
- ValidationRule.cs
- Logging.cs
- RightsManagementInformation.cs
- UriSchemeKeyedCollection.cs
- IImplicitResourceProvider.cs
- TypeResolvingOptionsAttribute.cs
- MissingManifestResourceException.cs
- UITypeEditor.cs
- safesecurityhelperavalon.cs
- ConfigurationProperty.cs
- NamespaceMapping.cs
- ReliabilityContractAttribute.cs
- CorePropertiesFilter.cs
- SmtpAuthenticationManager.cs
- FlowDocumentScrollViewer.cs
- Knowncolors.cs
- FontResourceCache.cs
- ComponentGuaranteesAttribute.cs
- dataobject.cs
- RemotingConfiguration.cs
- Compilation.cs
- Visitors.cs
- ImageMap.cs
- ClientFormsIdentity.cs
- RemoteWebConfigurationHost.cs
- Zone.cs
- DeviceContext2.cs
- RequestTimeoutManager.cs
- ContainerActivationHelper.cs
- XmlIncludeAttribute.cs
- SynchronousSendBindingElement.cs
- XmlSchemaComplexContentExtension.cs
- ColorConvertedBitmap.cs
- ClickablePoint.cs
- PropertyDescriptor.cs
- ContextMenuStrip.cs