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
- ButtonAutomationPeer.cs
- X509SecurityTokenProvider.cs
- SyndicationDeserializer.cs
- XmlExpressionDumper.cs
- SecurityPermission.cs
- ConsumerConnectionPoint.cs
- DataTrigger.cs
- ReferenceConverter.cs
- NavigationHelper.cs
- VirtualPathProvider.cs
- Literal.cs
- SharedMemory.cs
- SmiRecordBuffer.cs
- DelegatingConfigHost.cs
- AnnouncementEndpoint.cs
- SByteStorage.cs
- DataGridAddNewRow.cs
- ButtonBase.cs
- HandlerMappingMemo.cs
- BindingOperations.cs
- CacheSection.cs
- BamlResourceDeserializer.cs
- QueueTransferProtocol.cs
- CodeTypeDelegate.cs
- EventData.cs
- EnumerableCollectionView.cs
- SiteMapPath.cs
- ToolStripSettings.cs
- DisableDpiAwarenessAttribute.cs
- MethodBody.cs
- XmlSigningNodeWriter.cs
- Focus.cs
- EncryptionUtility.cs
- ParserStack.cs
- FixedSOMTableRow.cs
- SqlCommandSet.cs
- BrushMappingModeValidation.cs
- SizeAnimationClockResource.cs
- PriorityQueue.cs
- SerialPort.cs
- OpCodes.cs
- BamlRecordReader.cs
- OpenFileDialog.cs
- HttpCachePolicyElement.cs
- MaskedTextProvider.cs
- XhtmlBasicValidatorAdapter.cs
- TextServicesDisplayAttribute.cs
- TabControlCancelEvent.cs
- PageCodeDomTreeGenerator.cs
- LineProperties.cs
- OuterGlowBitmapEffect.cs
- PocoEntityKeyStrategy.cs
- XPathSelectionIterator.cs
- MD5.cs
- RuleSettings.cs
- ThreadInterruptedException.cs
- XmlDocumentFragment.cs
- GridViewDeleteEventArgs.cs
- CharEnumerator.cs
- FilteredReadOnlyMetadataCollection.cs
- WebPartRestoreVerb.cs
- FileCodeGroup.cs
- safelinkcollection.cs
- WindowsIdentity.cs
- SignedXml.cs
- PrintDialogDesigner.cs
- GetKeyedHashRequest.cs
- BridgeDataRecord.cs
- WsatExtendedInformation.cs
- DesignerTransactionCloseEvent.cs
- ClosureBinding.cs
- ZeroOpNode.cs
- HandleScope.cs
- TransportManager.cs
- SafeCryptContextHandle.cs
- ServerProtocol.cs
- AsymmetricKeyExchangeFormatter.cs
- EventWaitHandle.cs
- PolicyStatement.cs
- CompilerCollection.cs
- RuntimeCompatibilityAttribute.cs
- SystemDropShadowChrome.cs
- ViewStateModeByIdAttribute.cs
- IDQuery.cs
- ListChangedEventArgs.cs
- CodeNamespaceImportCollection.cs
- GrabHandleGlyph.cs
- NonBatchDirectoryCompiler.cs
- WebPartChrome.cs
- XmlSerializerFactory.cs
- OptimizerPatterns.cs
- TagPrefixInfo.cs
- DataBindingExpressionBuilder.cs
- ProjectionPathBuilder.cs
- DataTableReader.cs
- StructuralObject.cs
- OutputCacheSettingsSection.cs
- CmsUtils.cs
- ConcurrencyMode.cs
- DataServiceOperationContext.cs