Code:
/ FXUpdate3074 / FXUpdate3074 / 1.1 / untmp / whidbey / QFE / ndp / fx / src / xsp / System / Web / Compilation / AppSettingsExpressionBuilder.cs / 1 / AppSettingsExpressionBuilder.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; [ExpressionPrefix("AppSettings")] [ExpressionEditor("System.Web.UI.Design.AppSettingsExpressionEditor, " + AssemblyRef.SystemDesign)] [AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)] public class AppSettingsExpressionBuilder : ExpressionBuilder { public override bool SupportsEvaluate { get { return true; } } public override CodeExpression GetCodeExpression(BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context) { if (entry.DeclaringType == null || entry.PropertyInfo == null) { return new CodeMethodInvokeExpression( new CodeTypeReferenceExpression(this.GetType()), "GetAppSetting", new CodePrimitiveExpression(entry.Expression.Trim())); } else { return new CodeMethodInvokeExpression( new CodeTypeReferenceExpression(this.GetType()), "GetAppSetting", new CodePrimitiveExpression(entry.Expression.Trim()), new CodeTypeOfExpression(entry.DeclaringType), new CodePrimitiveExpression(entry.PropertyInfo.Name)); } } public override object EvaluateExpression(object target, BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context) { return GetAppSetting(entry.Expression, target.GetType(), entry.PropertyInfo.Name); } public static object GetAppSetting(string key) { string value = ConfigurationManager.AppSettings[key]; if (value == null) { throw new InvalidOperationException(SR.GetString(SR.AppSetting_not_found, key)); } return value; } public static object GetAppSetting(string key, Type targetType, string propertyName) { string value = ConfigurationManager.AppSettings[key]; if (targetType != null) { PropertyDescriptor propDesc = TypeDescriptor.GetProperties(targetType)[propertyName]; if (propDesc != null) { if (propDesc.PropertyType != typeof(string)) { TypeConverter converter = propDesc.Converter; if (converter.CanConvertFrom(typeof(string))) { return converter.ConvertFrom(value); } else { throw new InvalidOperationException(SR.GetString(SR.AppSetting_not_convertible, value, propDesc.PropertyType.Name, propDesc.Name)); } } } } if (value == null) { throw new InvalidOperationException(SR.GetString(SR.AppSetting_not_found, key)); } return value; } } } // 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
- OracleTransaction.cs
- RestClientProxyHandler.cs
- SqlPersonalizationProvider.cs
- UIElement3D.cs
- PaintValueEventArgs.cs
- FileVersionInfo.cs
- SmtpFailedRecipientsException.cs
- DataGridViewCellPaintingEventArgs.cs
- PreservationFileWriter.cs
- BitConverter.cs
- DbConnectionStringCommon.cs
- CodeParameterDeclarationExpression.cs
- PagePropertiesChangingEventArgs.cs
- X509RawDataKeyIdentifierClause.cs
- CodeThrowExceptionStatement.cs
- ToolboxComponentsCreatedEventArgs.cs
- BindableAttribute.cs
- InputLangChangeRequestEvent.cs
- SerTrace.cs
- XPathNavigatorReader.cs
- SmtpDigestAuthenticationModule.cs
- WindowsGraphicsWrapper.cs
- FunctionDetailsReader.cs
- CopyAttributesAction.cs
- Quad.cs
- Events.cs
- SimpleHandlerBuildProvider.cs
- BitmapImage.cs
- PartBasedPackageProperties.cs
- LocalizeDesigner.cs
- ZipIOExtraField.cs
- securitymgrsite.cs
- Base64Stream.cs
- MimeParameterWriter.cs
- XmlTypeMapping.cs
- InternalRelationshipCollection.cs
- JournalEntryStack.cs
- PriorityBindingExpression.cs
- Stream.cs
- Grant.cs
- FloaterParagraph.cs
- XsltContext.cs
- WinFormsSecurity.cs
- ProgressBar.cs
- TextBox.cs
- MethodMessage.cs
- ImageListUtils.cs
- PixelFormats.cs
- HttpApplicationStateBase.cs
- SelectionPattern.cs
- GridViewCellAutomationPeer.cs
- MessageBodyMemberAttribute.cs
- JsonFormatReaderGenerator.cs
- OrderedEnumerableRowCollection.cs
- WebFormDesignerActionService.cs
- Cursor.cs
- RemoteCryptoSignHashRequest.cs
- HandlerElementCollection.cs
- Rect3D.cs
- NotifyIcon.cs
- QilDataSource.cs
- ObjectFullSpanRewriter.cs
- StdValidatorsAndConverters.cs
- AssemblyCollection.cs
- SystemIPv4InterfaceProperties.cs
- DiagnosticTraceSource.cs
- Transform3DCollection.cs
- storepermissionattribute.cs
- ServiceThrottle.cs
- TextHidden.cs
- dbenumerator.cs
- InputReport.cs
- HTMLTextWriter.cs
- ToggleButtonAutomationPeer.cs
- bidPrivateBase.cs
- XmlILConstructAnalyzer.cs
- BitmapMetadataEnumerator.cs
- Environment.cs
- DurableEnlistmentState.cs
- BlockingCollection.cs
- DataGridPagerStyle.cs
- ComponentConverter.cs
- HtmlInputRadioButton.cs
- JoinElimination.cs
- ActivityStatusChangeEventArgs.cs
- WhitespaceRuleReader.cs
- DATA_BLOB.cs
- HotCommands.cs
- ColumnMap.cs
- FolderLevelBuildProviderAppliesToAttribute.cs
- Deserializer.cs
- RepeaterItemEventArgs.cs
- TreeBuilder.cs
- WebSysDefaultValueAttribute.cs
- AnnotationAdorner.cs
- BitmapMetadataBlob.cs
- XPathChildIterator.cs
- ReadOnlyCollection.cs
- RequestCachePolicyConverter.cs
- SpoolingTaskBase.cs