Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / xsp / System / Web / Compilation / ConnectionStringsExpressionBuilder.cs / 1 / ConnectionStringsExpressionBuilder.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.Compilation { using System; using System.Security.Permissions; using System.CodeDom; using System.Configuration; using System.Globalization; using System.Web.UI; [ExpressionPrefix("ConnectionStrings")] [ExpressionEditor("System.Web.UI.Design.ConnectionStringsExpressionEditor, " + AssemblyRef.SystemDesign)] [AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)] public class ConnectionStringsExpressionBuilder : ExpressionBuilder { public override bool SupportsEvaluate { get { return true; } } public override object ParseExpression(string expression, Type propertyType, ExpressionBuilderContext context) { // This code is also copied in ConnectionStringsExpressionEditor.ParseExpression() const string connectionStringSuffix = ".connectionstring"; const string providerNameSuffix = ".providername"; string name = String.Empty; bool connectionString = true; if (expression != null) { if (expression.EndsWith(connectionStringSuffix, StringComparison.OrdinalIgnoreCase)) { name = expression.Substring(0, expression.Length - connectionStringSuffix.Length); } else { if (expression.EndsWith(providerNameSuffix, StringComparison.OrdinalIgnoreCase)) { connectionString = false; name = expression.Substring(0, expression.Length - providerNameSuffix.Length); } else { name = expression; } } } return new Pair(name, connectionString); } public override CodeExpression GetCodeExpression(BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context) { Pair p = (Pair)parsedData; string name = (string)p.First; bool connectionString = (bool)p.Second; if (connectionString) { return new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(this.GetType()), "GetConnectionString", new CodePrimitiveExpression(name)); } else { return new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(this.GetType()), "GetConnectionStringProviderName", new CodePrimitiveExpression(name)); } } public override object EvaluateExpression(object target, BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context) { Pair p = (Pair)parsedData; string name = (string)p.First; bool connectionString = (bool)p.Second; ConnectionStringSettings setting = ConfigurationManager.ConnectionStrings[name]; if (connectionString) { return GetConnectionString(name); } else { return GetConnectionStringProviderName(name); } } public static string GetConnectionStringProviderName(string connectionStringName) { ConnectionStringSettings setting = ConfigurationManager.ConnectionStrings[connectionStringName]; if (setting == null) { throw new InvalidOperationException(SR.GetString(SR.Connection_string_not_found, connectionStringName)); } return setting.ProviderName; } public static string GetConnectionString(string connectionStringName) { ConnectionStringSettings setting = ConfigurationManager.ConnectionStrings[connectionStringName]; if (setting == null) { throw new InvalidOperationException(SR.GetString(SR.Connection_string_not_found, connectionStringName)); } return setting.ConnectionString; } } }
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SqlDataRecord.cs
- ArgumentNullException.cs
- ListViewEditEventArgs.cs
- MSG.cs
- input.cs
- GroupLabel.cs
- CheckBoxPopupAdapter.cs
- TextElementCollection.cs
- CngKeyCreationParameters.cs
- Positioning.cs
- MenuItemStyleCollectionEditor.cs
- SubtreeProcessor.cs
- Enlistment.cs
- XPathQueryGenerator.cs
- XmlNodeList.cs
- AutoGeneratedField.cs
- ValidationResult.cs
- COM2IDispatchConverter.cs
- PersonalizationProviderCollection.cs
- ItemList.cs
- InsufficientExecutionStackException.cs
- TileModeValidation.cs
- HttpResponseInternalWrapper.cs
- UInt64Converter.cs
- SqlDataReader.cs
- DefaultTextStoreTextComposition.cs
- Margins.cs
- BitmapEffectOutputConnector.cs
- TraceInternal.cs
- UIPropertyMetadata.cs
- TrackingWorkflowEventArgs.cs
- WebPartTransformer.cs
- CaseCqlBlock.cs
- XmlUnspecifiedAttribute.cs
- PageEventArgs.cs
- TreeView.cs
- ConstrainedDataObject.cs
- ManagedCodeMarkers.cs
- Light.cs
- CommandID.cs
- ToolStripItem.cs
- FileInfo.cs
- AuthenticatingEventArgs.cs
- ClientRoleProvider.cs
- AuditLogLocation.cs
- FormParameter.cs
- DataSourceControlBuilder.cs
- ApplicationBuildProvider.cs
- ServicePointManager.cs
- MarkupProperty.cs
- IfAction.cs
- HeaderUtility.cs
- StaticSiteMapProvider.cs
- GeneratedView.cs
- SubqueryRules.cs
- DataViewSettingCollection.cs
- ConnectionStringsSection.cs
- ButtonChrome.cs
- CompilationRelaxations.cs
- SHA512.cs
- MouseActionConverter.cs
- HMACMD5.cs
- TabOrder.cs
- KeyboardDevice.cs
- AdvancedBindingEditor.cs
- SignerInfo.cs
- PropVariant.cs
- ProcessModelInfo.cs
- MouseBinding.cs
- TriggerActionCollection.cs
- Control.cs
- CallContext.cs
- MessagingActivityHelper.cs
- CoreSwitches.cs
- RoleBoolean.cs
- RoutedEventConverter.cs
- RootBrowserWindow.cs
- RequestQueue.cs
- ACE.cs
- SqlDataSourceView.cs
- BitmapEffectInput.cs
- NumericUpDownAccelerationCollection.cs
- VirtualDirectoryMapping.cs
- InstalledFontCollection.cs
- ProtocolsSection.cs
- CredentialCache.cs
- Helper.cs
- SSmlParser.cs
- ReflectionPermission.cs
- RequestQueue.cs
- TransformedBitmap.cs
- RadioButtonFlatAdapter.cs
- MetaData.cs
- SerializationEventsCache.cs
- List.cs
- FileAuthorizationModule.cs
- CompositeScriptReferenceEventArgs.cs
- TrustLevelCollection.cs
- XmlJsonReader.cs
- AddInController.cs