Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Extensions / UI / WebControls / Expressions / SearchExpression.cs / 1305376 / SearchExpression.cs
#if ORYX_VNEXT namespace Microsoft.Web.Data.UI.WebControls.Expressions { #else namespace System.Web.UI.WebControls.Expressions { #endif using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Linq.Expressions; using System.Web.Resources; using System.Web.UI; using System.Web.UI.WebControls; public class SearchExpression : ParameterDataSourceExpression { public string DataFields { get { return (string)ViewState["DataFields"] ?? String.Empty; } set { ViewState["DataFields"] = value; } } public SearchType SearchType { get { object o = ViewState["SearchType"]; return o != null ? (SearchType)o : SearchType.StartsWith; } set { ViewState["SearchType"] = value; } } public StringComparison ComparisonType { get { object o = ViewState["ComparisonType"]; return o != null ? (StringComparison)o : StringComparison.OrdinalIgnoreCase; } set { ViewState["ComparisonType"] = value; } } public override IQueryable GetQueryable(IQueryable source) { if (source == null) { return null; } if ((DataFields == null) || String.IsNullOrEmpty(DataFields.Trim())) { throw new InvalidOperationException(AtlasWeb.Expressions_DataFieldRequired); } IDictionaryvalues = GetValues(); if (values.Count == 0) { throw new InvalidOperationException(AtlasWeb.SearchExpression_ParameterRequired); } string query = Convert.ToString(values.First().Value, CultureInfo.CurrentCulture); if (String.IsNullOrEmpty(query)) { return null; } string[] properties = DataFields.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); // Use the or expression to or the fields together List searchExpressions = new List (); ParameterExpression parameterExpression = Expression.Parameter(source.ElementType, String.Empty); foreach (string p in properties) { Expression property = ExpressionHelper.CreatePropertyExpression(parameterExpression, p.Trim()); searchExpressions.Add(CreateCallExpression(property, query)); } return ExpressionHelper.Where(source, Expression.Lambda(ExpressionHelper.Or(searchExpressions), parameterExpression)); } private Expression CreateCallExpression(Expression property, string query) { // LINQ to SQL does not support the overloads StartsWith(string, StringComparer) or EndsWith(string, StringComparer) // and Contains has not overload that takes a StringComparer if (SearchType == SearchType.Contains || (ViewState["ComparisonType"] == null)) { return Expression.Call(property, SearchType.ToString(), Type.EmptyTypes, Expression.Constant(query, property.Type)); } return Expression.Call(property, SearchType.ToString(), Type.EmptyTypes, Expression.Constant(query, property.Type), Expression.Constant(ComparisonType)); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ISAPIApplicationHost.cs
- updateconfighost.cs
- ClientSideProviderDescription.cs
- FontDriver.cs
- SystemWebSectionGroup.cs
- FilterElement.cs
- ValidatorCompatibilityHelper.cs
- TagPrefixCollection.cs
- XmlSchemaExporter.cs
- RegexCompilationInfo.cs
- UniqueConstraint.cs
- DSASignatureFormatter.cs
- MetricEntry.cs
- ServiceChannelManager.cs
- LastQueryOperator.cs
- DocumentApplicationJournalEntry.cs
- WSHttpSecurity.cs
- AxWrapperGen.cs
- PolicyManager.cs
- TextBoxAutomationPeer.cs
- StylusPointPropertyInfo.cs
- NullableConverter.cs
- TreeIterator.cs
- PropertyInformationCollection.cs
- ReadContentAsBinaryHelper.cs
- FlowLayoutPanel.cs
- Double.cs
- LineServicesRun.cs
- TextBounds.cs
- DispatcherProcessingDisabled.cs
- DocumentViewer.cs
- QilParameter.cs
- TreeNodeStyleCollection.cs
- MatrixAnimationBase.cs
- FlowNode.cs
- XamlFilter.cs
- GroupItemAutomationPeer.cs
- MobileTextWriter.cs
- XmlObjectSerializerWriteContextComplexJson.cs
- StateManagedCollection.cs
- EventLogRecord.cs
- StreamGeometryContext.cs
- ManipulationBoundaryFeedbackEventArgs.cs
- StringStorage.cs
- PagedControl.cs
- WebSysDefaultValueAttribute.cs
- SmtpNegotiateAuthenticationModule.cs
- PrincipalPermission.cs
- XPathQilFactory.cs
- MobileListItemCollection.cs
- MetaType.cs
- BaseValidator.cs
- GetWinFXPath.cs
- SettingsPropertyValue.cs
- DynamicFilter.cs
- SByteConverter.cs
- DiscoveryDocumentSerializer.cs
- DataGridViewMethods.cs
- StoryFragments.cs
- DependencyObjectCodeDomSerializer.cs
- XmlNamespaceManager.cs
- ProjectionPruner.cs
- UInt32Converter.cs
- XPathNode.cs
- SpeechDetectedEventArgs.cs
- ApplyHostConfigurationBehavior.cs
- Latin1Encoding.cs
- RoleManagerEventArgs.cs
- GridViewCancelEditEventArgs.cs
- SettingsPropertyWrongTypeException.cs
- HeaderedItemsControl.cs
- TextTreeInsertUndoUnit.cs
- PartDesigner.cs
- CodeNamespaceImport.cs
- DefaultCommandConverter.cs
- SimpleWebHandlerParser.cs
- ErrorProvider.cs
- XamlBrushSerializer.cs
- SoundPlayer.cs
- StrongNamePublicKeyBlob.cs
- XPathNodeHelper.cs
- DataControlFieldCell.cs
- ReflectionHelper.cs
- HtmlShimManager.cs
- UpdateTranslator.cs
- PauseStoryboard.cs
- EUCJPEncoding.cs
- Permission.cs
- ChannelCacheDefaults.cs
- PositiveTimeSpanValidator.cs
- ReflectionPermission.cs
- HostProtectionPermission.cs
- JournalEntryStack.cs
- SessionEndedEventArgs.cs
- TextEditorThreadLocalStore.cs
- Pair.cs
- TdsParserStateObject.cs
- SpellerHighlightLayer.cs
- TextShapeableCharacters.cs
- LockCookie.cs