Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Web / Compilation / AppSettingsExpressionBuilder.cs / 1305376 / 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)] 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SoundPlayer.cs
- RNGCryptoServiceProvider.cs
- HMACSHA1.cs
- querybuilder.cs
- CodeTypeReferenceExpression.cs
- TabControl.cs
- XsdBuilder.cs
- TextTabProperties.cs
- CollectionType.cs
- ProgressBarHighlightConverter.cs
- DynamicValidatorEventArgs.cs
- RankException.cs
- OutOfMemoryException.cs
- OrderByExpression.cs
- DefaultTraceListener.cs
- MailMessage.cs
- XmlFormatWriterGenerator.cs
- COM2FontConverter.cs
- RequestQueryProcessor.cs
- XmlMembersMapping.cs
- EntitySqlQueryState.cs
- CodeDomSerializationProvider.cs
- SqlErrorCollection.cs
- WebPartVerbCollection.cs
- _NativeSSPI.cs
- SrgsElement.cs
- DashStyle.cs
- LambdaReference.cs
- FormCollection.cs
- DesignerVerbCollection.cs
- RowUpdatedEventArgs.cs
- WorkflowPageSetupDialog.cs
- basenumberconverter.cs
- FillRuleValidation.cs
- XamlValidatingReader.cs
- MDIWindowDialog.cs
- Input.cs
- AutomationPropertyInfo.cs
- updateconfighost.cs
- ProxyAttribute.cs
- PeerResolverMode.cs
- DiscoveryCallbackBehavior.cs
- TypeDelegator.cs
- Image.cs
- WebEvents.cs
- Pair.cs
- AsnEncodedData.cs
- MulticastDelegate.cs
- OperationAbortedException.cs
- LinearKeyFrames.cs
- TextContainerHelper.cs
- AccessControlList.cs
- CallbackHandler.cs
- CSharpCodeProvider.cs
- ReferencedCollectionType.cs
- DataRowChangeEvent.cs
- ConsumerConnectionPointCollection.cs
- Container.cs
- StringReader.cs
- SqlFacetAttribute.cs
- ResXDataNode.cs
- LinearKeyFrames.cs
- ProviderConnectionPointCollection.cs
- WindowsGrip.cs
- Triangle.cs
- ClientSettingsSection.cs
- FontStyle.cs
- DescendentsWalkerBase.cs
- SqlMethodCallConverter.cs
- ImageSourceValueSerializer.cs
- AppSettingsReader.cs
- Configuration.cs
- ServiceHttpModule.cs
- DeclaredTypeElementCollection.cs
- PropertyOverridesTypeEditor.cs
- SemaphoreSlim.cs
- Int32KeyFrameCollection.cs
- RoleService.cs
- LeaseManager.cs
- AttachmentCollection.cs
- SourceSwitch.cs
- LabelEditEvent.cs
- DataGridParentRows.cs
- TemplateParser.cs
- ValueType.cs
- DrawingServices.cs
- TimeSpanMinutesOrInfiniteConverter.cs
- DataPagerFieldItem.cs
- RenderingBiasValidation.cs
- RuleProcessor.cs
- _Events.cs
- Assembly.cs
- ConfigurationElement.cs
- XmlTextAttribute.cs
- GorillaCodec.cs
- LinqDataView.cs
- WebPartVerbsEventArgs.cs
- DecoderFallbackWithFailureFlag.cs
- AlgoModule.cs
- InternalPermissions.cs