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
- SetIterators.cs
- DateTime.cs
- KeyboardEventArgs.cs
- XmlAttribute.cs
- WebPartConnectionsCancelEventArgs.cs
- RewritingSimplifier.cs
- ValueTypeFieldReference.cs
- DynamicQueryStringParameter.cs
- OpenTypeCommon.cs
- controlskin.cs
- ListItemCollection.cs
- DocComment.cs
- XmlStreamStore.cs
- ToolStripDropDownButton.cs
- NavigationHelper.cs
- DbConnectionPoolOptions.cs
- Error.cs
- ProtectedConfiguration.cs
- EntityContainerAssociationSetEnd.cs
- ContentPathSegment.cs
- SAPIEngineTypes.cs
- WriteableOnDemandStream.cs
- LinkDescriptor.cs
- Sql8ExpressionRewriter.cs
- ResolvedKeyFrameEntry.cs
- DurableServiceAttribute.cs
- _StreamFramer.cs
- InteropTrackingRecord.cs
- RedistVersionInfo.cs
- NotImplementedException.cs
- NominalTypeEliminator.cs
- NameValueConfigurationElement.cs
- ClassHandlersStore.cs
- VoiceObjectToken.cs
- DispatcherExceptionEventArgs.cs
- DbMetaDataCollectionNames.cs
- BinHexDecoder.cs
- DataGridViewBindingCompleteEventArgs.cs
- SHA1.cs
- ViewStateModeByIdAttribute.cs
- DictionaryCustomTypeDescriptor.cs
- EventSourceCreationData.cs
- UIElement3D.cs
- LOSFormatter.cs
- PrinterSettings.cs
- DBDataPermissionAttribute.cs
- MenuScrollingVisibilityConverter.cs
- HttpDictionary.cs
- RIPEMD160.cs
- AddingNewEventArgs.cs
- SvcMapFile.cs
- PageAdapter.cs
- ConfigurationCollectionAttribute.cs
- OdbcEnvironmentHandle.cs
- RichTextBox.cs
- MetadataArtifactLoaderResource.cs
- SimpleMailWebEventProvider.cs
- ExpressionBindingCollection.cs
- _ScatterGatherBuffers.cs
- DocumentPageView.cs
- ErrorTableItemStyle.cs
- EmptyStringExpandableObjectConverter.cs
- Missing.cs
- DataViewSettingCollection.cs
- WizardForm.cs
- ProcessHostServerConfig.cs
- PolyBezierSegment.cs
- TextBoxAutomationPeer.cs
- WebZoneDesigner.cs
- ComponentRenameEvent.cs
- Style.cs
- _SslStream.cs
- ScriptManagerProxy.cs
- dataobject.cs
- NamespaceCollection.cs
- SendingRequestEventArgs.cs
- BufferedReadStream.cs
- AppDomainEvidenceFactory.cs
- HashAlgorithm.cs
- PrintPageEvent.cs
- Point3DAnimation.cs
- HtmlUtf8RawTextWriter.cs
- SessionStateModule.cs
- BitmapCacheBrush.cs
- IODescriptionAttribute.cs
- ImageClickEventArgs.cs
- ScriptManager.cs
- TextElementEnumerator.cs
- Events.cs
- RequestContext.cs
- SwitchCase.cs
- ContentWrapperAttribute.cs
- MinimizableAttributeTypeConverter.cs
- MappingSource.cs
- QuotedStringFormatReader.cs
- DeobfuscatingStream.cs
- lengthconverter.cs
- WebEventTraceProvider.cs
- InsufficientMemoryException.cs
- WebPartHeaderCloseVerb.cs