Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Web / Compilation / RouteValueExpressionBuilder.cs / 1305376 / RouteValueExpressionBuilder.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.Compilation { using System; using System.Security.Permissions; using System.CodeDom; using System.ComponentModel; using System.Configuration; using System.Diagnostics; using System.Web.UI; using System.Web.Routing; using System.Collections.Generic; [ExpressionPrefix("Routes")] [ExpressionEditor("System.Web.UI.Design.RouteValueExpressionEditor, " + AssemblyRef.SystemDesign)] public class RouteValueExpressionBuilder : ExpressionBuilder { public override bool SupportsEvaluate { get { return true; } } public override CodeExpression GetCodeExpression(BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context) { return new CodeMethodInvokeExpression( new CodeTypeReferenceExpression(this.GetType()), "GetRouteValue", new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "Page"), new CodePrimitiveExpression(entry.Expression.Trim()), new CodeTypeOfExpression(new CodeTypeReference(entry.ControlType)), new CodePrimitiveExpression(entry.Name) ); } public override object EvaluateExpression(object target, BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context) { // Target should always be a control Control control = target as Control; if (control == null) return null; return GetRouteValue(context.TemplateControl.Page, entry.Expression.Trim(), entry.ControlType, entry.Name); } internal static object ConvertRouteValue(object value, Type controlType, string propertyName) { // Try to do any type converting necessary for the property set if (controlType != null && !String.IsNullOrEmpty(propertyName)) { PropertyDescriptor propDesc = TypeDescriptor.GetProperties(controlType)[propertyName]; if (propDesc != null) { if (propDesc.PropertyType != typeof(string)) { TypeConverter converter = propDesc.Converter; if (converter.CanConvertFrom(typeof(string))) { return converter.ConvertFrom(value); } } } } return value; } // Format will be <%$ RouteValue: Key %>, controlType,propertyName are used to figure out what typeconverter to use public static object GetRouteValue(Page page, string key, Type controlType, string propertyName) { if (page == null || String.IsNullOrEmpty(key) || page.RouteData == null) { return null; } return ConvertRouteValue(page.RouteData.Values[key], controlType, propertyName); } } } // 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
- ConnectionStringsExpressionBuilder.cs
- CheckedListBox.cs
- CriticalFinalizerObject.cs
- _UriSyntax.cs
- RichTextBoxDesigner.cs
- XPathExpr.cs
- MailAddress.cs
- ConstructorBuilder.cs
- ECDiffieHellmanPublicKey.cs
- DataTableCollection.cs
- ControlSerializer.cs
- ExpressionStringBuilder.cs
- FontSourceCollection.cs
- DataReceivedEventArgs.cs
- SmtpNtlmAuthenticationModule.cs
- DataServiceHost.cs
- ScaleTransform3D.cs
- DataErrorValidationRule.cs
- UniqueSet.cs
- XmlFileEditor.cs
- SimpleHandlerFactory.cs
- SmiRecordBuffer.cs
- TreeNodeBinding.cs
- SortFieldComparer.cs
- CatalogZoneBase.cs
- _ConnectOverlappedAsyncResult.cs
- CodeEventReferenceExpression.cs
- ProxyWebPart.cs
- TypeBrowserDialog.cs
- TypedTableBase.cs
- TextMetrics.cs
- DropShadowEffect.cs
- VSWCFServiceContractGenerator.cs
- UpdateProgress.cs
- ControlAdapter.cs
- UnmanagedBitmapWrapper.cs
- HostUtils.cs
- SQLBinaryStorage.cs
- InvalidWMPVersionException.cs
- WindowsFormsEditorServiceHelper.cs
- LiteralSubsegment.cs
- GridViewRowPresenterBase.cs
- ShaderEffect.cs
- GridViewRowPresenterBase.cs
- VolatileEnlistmentMultiplexing.cs
- HttpAsyncResult.cs
- DispatchWrapper.cs
- XmlBaseReader.cs
- DoubleAnimationClockResource.cs
- ChannelBinding.cs
- FtpCachePolicyElement.cs
- TypeTypeConverter.cs
- PointUtil.cs
- WinInetCache.cs
- PropertyGridView.cs
- UnsafeNativeMethods.cs
- UserControl.cs
- AssertValidation.cs
- RichTextBox.cs
- Highlights.cs
- DaylightTime.cs
- InheritedPropertyChangedEventArgs.cs
- WebZone.cs
- ClearTypeHintValidation.cs
- MetadataItem.cs
- RenamedEventArgs.cs
- CompilationRelaxations.cs
- MessageFilter.cs
- EdmType.cs
- WindowsAuthenticationEventArgs.cs
- BindingElementExtensionElement.cs
- WebReferencesBuildProvider.cs
- TypedElement.cs
- SerializationFieldInfo.cs
- RelatedView.cs
- CodeComment.cs
- bindurihelper.cs
- Button.cs
- ClrProviderManifest.cs
- ObjectNotFoundException.cs
- ToolZone.cs
- XmlLanguageConverter.cs
- ObjectAssociationEndMapping.cs
- FormsIdentity.cs
- CounterCreationDataCollection.cs
- PermissionSet.cs
- UserControl.cs
- DES.cs
- EncryptedPackageFilter.cs
- Vector3DValueSerializer.cs
- StrokeNodeOperations.cs
- ConfigPathUtility.cs
- EntityCollectionChangedParams.cs
- DbRetry.cs
- XmlSchemaParticle.cs
- XsltException.cs
- DATA_BLOB.cs
- DbParameterCollection.cs
- SecurityTokenResolver.cs
- Clause.cs