Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / Data / System / Data / Common / DbConnectionStringBuilder.cs / 1 / DbConnectionStringBuilder.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //[....] //----------------------------------------------------------------------------- namespace System.Data.Common { using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.Common; using System.Diagnostics; using System.Globalization; using System.Runtime.Serialization; using System.Security.Permissions; using System.Text; using System.Text.RegularExpressions; #if WINFSInternalOnly internal #else public #endif class DbConnectionStringBuilder : System.Collections.IDictionary, ICustomTypeDescriptor { // keyword->value currently listed in the connection string private Dictionary_currentValues; // cached connectionstring to avoid constant rebuilding // and to return a user's connectionstring as is until editing occurs private string _connectionString = ""; private PropertyDescriptorCollection _propertyDescriptors; private bool _browsableConnectionString = true; private readonly bool UseOdbcRules; private static int _objectTypeCount; // Bid counter internal readonly int _objectID = System.Threading.Interlocked.Increment(ref _objectTypeCount); public DbConnectionStringBuilder() { } public DbConnectionStringBuilder(bool useOdbcRules) { UseOdbcRules = useOdbcRules; } private ICollection Collection { get { return (ICollection)CurrentValues; } } private IDictionary Dictionary { get { return (IDictionary)CurrentValues; } } private Dictionary CurrentValues { get { Dictionary values = _currentValues; if (null == values) { values = new Dictionary (StringComparer.OrdinalIgnoreCase); _currentValues = values; } return values; } } object System.Collections.IDictionary.this[object keyword] { // delegate to this[string keyword] get { return this[ObjectToString(keyword)]; } set { this[ObjectToString(keyword)] = value; } } [Browsable(false)] public virtual object this[string keyword] { get { Bid.Trace(" %d#, keyword='%ls'\n", ObjectID, keyword); ADP.CheckArgumentNull(keyword, "keyword"); object value; if (CurrentValues.TryGetValue(keyword, out value)) { return value; } throw ADP.KeywordNotSupported(keyword); } set { ADP.CheckArgumentNull(keyword, "keyword"); bool flag = false; if (null != value) { string keyvalue = DbConnectionStringBuilderUtil.ConvertToString(value); DbConnectionOptions.ValidateKeyValuePair(keyword, keyvalue); flag = CurrentValues.ContainsKey(keyword); // store keyword/value pair CurrentValues[keyword] = keyvalue; } else { flag = Remove(keyword); } _connectionString = null; if (flag) { _propertyDescriptors = null; } } } [Browsable(false)] [DesignOnly(true)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] [EditorBrowsableAttribute(EditorBrowsableState.Never)] public bool BrowsableConnectionString { get { return _browsableConnectionString; } set { _browsableConnectionString = value; _propertyDescriptors = null; } } [RefreshPropertiesAttribute(RefreshProperties.All)] [ResCategoryAttribute(Res.DataCategory_Data)] [ResDescriptionAttribute(Res.DbConnectionString_ConnectionString)] public string ConnectionString { get { Bid.Trace(" %d#\n", ObjectID); string connectionString = _connectionString; if (null == connectionString) { StringBuilder builder = new StringBuilder(); foreach(string keyword in Keys) { object value; if (ShouldSerialize(keyword) && TryGetValue(keyword, out value)) { string keyvalue = (null != value) ? Convert.ToString(value, CultureInfo.InvariantCulture) : (string)null; AppendKeyValuePair(builder, keyword, keyvalue, UseOdbcRules); } } connectionString = builder.ToString(); _connectionString = connectionString; } return connectionString; } set { Bid.Trace(" %d#\n", ObjectID); DbConnectionOptions constr = new DbConnectionOptions(value, null, UseOdbcRules); string originalValue = ConnectionString; Clear(); try { for(NameValuePair pair = constr.KeyChain; null != pair; pair = pair.Next) { if (null != pair.Value) { this[pair.Name] = pair.Value; } else { Remove(pair.Name); } } _connectionString = null; } catch(ArgumentException) { // restore original string ConnectionString = originalValue; _connectionString = originalValue; throw; } } } [Browsable(false)] public virtual int Count { get { return CurrentValues.Count; } } [Browsable(false)] public bool IsReadOnly { get { return false; } } [Browsable(false)] public virtual bool IsFixedSize { get { return false; } } bool System.Collections.ICollection.IsSynchronized { get { return Collection.IsSynchronized; } } [Browsable(false)] public virtual ICollection Keys { get { Bid.Trace(" %d#\n", ObjectID); return Dictionary.Keys; } } internal int ObjectID { get { return _objectID; } } object System.Collections.ICollection.SyncRoot { get { return Collection.SyncRoot; } } [Browsable(false)] public virtual ICollection Values { get { Bid.Trace(" %d#\n", ObjectID); System.Collections.Generic.ICollection keys = (System.Collections.Generic.ICollection )Keys; System.Collections.Generic.IEnumerator keylist = keys.GetEnumerator(); object[] values = new object[keys.Count]; for(int i = 0; i < values.Length; ++i) { keylist.MoveNext(); values[i] = this[keylist.Current]; Debug.Assert(null != values[i], "null value " + keylist.Current); } return new System.Data.Common.ReadOnlyCollection
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DrawingCollection.cs
- Unit.cs
- PropertyGroupDescription.cs
- SqlNamer.cs
- Int16AnimationUsingKeyFrames.cs
- SqlInfoMessageEvent.cs
- TimelineGroup.cs
- OperatorExpressions.cs
- ErrorWebPart.cs
- WindowsScroll.cs
- BaseParser.cs
- AtomEntry.cs
- ColorMap.cs
- HitTestDrawingContextWalker.cs
- ReflectEventDescriptor.cs
- UserNamePasswordClientCredential.cs
- FirstQueryOperator.cs
- ToolStripContentPanel.cs
- XmlIlTypeHelper.cs
- DataGridViewComponentPropertyGridSite.cs
- TypeListConverter.cs
- Membership.cs
- CallContext.cs
- DesignerSerializerAttribute.cs
- BinaryFormatterWriter.cs
- TakeQueryOptionExpression.cs
- GridEntryCollection.cs
- OracleInfoMessageEventArgs.cs
- PageMediaType.cs
- DesignerAttribute.cs
- XsltArgumentList.cs
- QilParameter.cs
- EntityContainerAssociationSet.cs
- MenuTracker.cs
- RepeaterCommandEventArgs.cs
- RecordManager.cs
- XmlSchemaComplexContentRestriction.cs
- WebPartConnectionsConfigureVerb.cs
- XmlTextWriter.cs
- RealProxy.cs
- dbenumerator.cs
- sqlcontext.cs
- DataListCommandEventArgs.cs
- RightsManagementInformation.cs
- CollectionView.cs
- TrackingServices.cs
- EntityDataSourceContextDisposingEventArgs.cs
- ThemeableAttribute.cs
- XmlReflectionImporter.cs
- ReferenceAssemblyAttribute.cs
- _OSSOCK.cs
- HtmlImage.cs
- WebServiceData.cs
- WindowsGraphicsWrapper.cs
- _NativeSSPI.cs
- BitmapEffect.cs
- UdpReplyToBehavior.cs
- TreeNodeMouseHoverEvent.cs
- UDPClient.cs
- NonDualMessageSecurityOverHttpElement.cs
- BreakSafeBase.cs
- PkcsUtils.cs
- ListCardsInFileRequest.cs
- SapiRecognizer.cs
- IntSecurity.cs
- BamlLocalizabilityResolver.cs
- BrowserCapabilitiesCodeGenerator.cs
- RemotingConfiguration.cs
- Geometry3D.cs
- MissingSatelliteAssemblyException.cs
- ChannelManager.cs
- LineInfo.cs
- DelimitedListTraceListener.cs
- SoapProcessingBehavior.cs
- TdsEnums.cs
- XPathAncestorIterator.cs
- CodeRemoveEventStatement.cs
- TypefaceMetricsCache.cs
- CanonicalFontFamilyReference.cs
- SchemaTypeEmitter.cs
- SendKeys.cs
- ScriptReferenceEventArgs.cs
- EntityDataSourceViewSchema.cs
- ConfigurationCollectionAttribute.cs
- LinearGradientBrush.cs
- Rotation3D.cs
- HotSpot.cs
- WebPartEditVerb.cs
- DbConnectionFactory.cs
- PopOutPanel.cs
- Baml2006Reader.cs
- DesignerVerbCollection.cs
- Transform.cs
- OleDbParameter.cs
- EnumerationRangeValidationUtil.cs
- StrongNameIdentityPermission.cs
- ProtectedConfiguration.cs
- MessageQueueEnumerator.cs
- ExternalFile.cs
- ColorAnimation.cs