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
- CompilerHelpers.cs
- DatatypeImplementation.cs
- ResourceDescriptionAttribute.cs
- HwndTarget.cs
- SecurityNegotiationException.cs
- WorkflowOwnershipException.cs
- ProxyHwnd.cs
- HttpVersion.cs
- DbConnectionStringBuilder.cs
- CollectionChangeEventArgs.cs
- Simplifier.cs
- EdmTypeAttribute.cs
- DecimalStorage.cs
- InstanceData.cs
- ValidatorCollection.cs
- XsltFunctions.cs
- UInt64Converter.cs
- SafeNativeHandle.cs
- CodeMemberEvent.cs
- ZeroOpNode.cs
- FaultHandlingFilter.cs
- TempEnvironment.cs
- UpWmlMobileTextWriter.cs
- BoolExpression.cs
- Delay.cs
- EventData.cs
- CompensationHandlingFilter.cs
- CLSCompliantAttribute.cs
- assertwrapper.cs
- TypeElement.cs
- CapabilitiesState.cs
- SqlResolver.cs
- DataKeyArray.cs
- TableCellAutomationPeer.cs
- DbFunctionCommandTree.cs
- QuaternionValueSerializer.cs
- FormatterConverter.cs
- ShaderEffect.cs
- UnsafeNativeMethods.cs
- XmlHierarchicalEnumerable.cs
- OleDbInfoMessageEvent.cs
- XmlHierarchyData.cs
- BlobPersonalizationState.cs
- ReferenceService.cs
- ReturnValue.cs
- FlowPosition.cs
- PropertyMappingExceptionEventArgs.cs
- QuaternionRotation3D.cs
- Propagator.JoinPropagator.JoinPredicateVisitor.cs
- MatchingStyle.cs
- TargetInvocationException.cs
- GridSplitter.cs
- QualifiedCellIdBoolean.cs
- TextSpan.cs
- Listbox.cs
- OdbcDataAdapter.cs
- CodeNamespaceImport.cs
- HttpApplication.cs
- DocumentSequence.cs
- HMACRIPEMD160.cs
- CryptoHelper.cs
- FacetEnabledSchemaElement.cs
- Process.cs
- MultiBindingExpression.cs
- LoginDesigner.cs
- TypePropertyEditor.cs
- WizardPanel.cs
- Token.cs
- RoleService.cs
- PlainXmlDeserializer.cs
- JsonFormatGeneratorStatics.cs
- X509CertificateCollection.cs
- ToolboxItemFilterAttribute.cs
- Hex.cs
- ArglessEventHandlerProxy.cs
- SqlRowUpdatedEvent.cs
- ScrollProperties.cs
- NonBatchDirectoryCompiler.cs
- WebScriptMetadataFormatter.cs
- FontSizeConverter.cs
- SupportingTokenListenerFactory.cs
- FilterFactory.cs
- IconEditor.cs
- Math.cs
- DataSourceControlBuilder.cs
- FormsAuthenticationEventArgs.cs
- StrokeCollectionConverter.cs
- MimeMapping.cs
- PropertyDescriptors.cs
- linebase.cs
- TdsParserStateObject.cs
- EntitySqlException.cs
- VariableAction.cs
- MdImport.cs
- GridViewCancelEditEventArgs.cs
- PersonalizableTypeEntry.cs
- DataControlFieldCell.cs
- DrawingAttributesDefaultValueFactory.cs
- Panel.cs
- ChtmlCalendarAdapter.cs