Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Data / System / Data / Common / DbConnectionStringBuilder.cs / 1305376 / 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;
public 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
- HelpEvent.cs
- Formatter.cs
- KeyPressEvent.cs
- AuthenticateEventArgs.cs
- BamlResourceDeserializer.cs
- ObjectDataSource.cs
- _ReceiveMessageOverlappedAsyncResult.cs
- DrawToolTipEventArgs.cs
- ToolStripPanelCell.cs
- XMLSchema.cs
- PropertyChangedEventArgs.cs
- TimerElapsedEvenArgs.cs
- WriteTimeStream.cs
- WorkItem.cs
- Positioning.cs
- IndentTextWriter.cs
- DoubleCollectionValueSerializer.cs
- LayoutExceptionEventArgs.cs
- SqlConnectionPoolGroupProviderInfo.cs
- TPLETWProvider.cs
- SortFieldComparer.cs
- InputBuffer.cs
- EntityContainer.cs
- MessageDescriptionCollection.cs
- RootDesignerSerializerAttribute.cs
- AutomationPropertyInfo.cs
- EventDescriptor.cs
- TextBoxBase.cs
- RandomNumberGenerator.cs
- PatternMatchRules.cs
- FilteredDataSetHelper.cs
- MetadataCache.cs
- DateTimeStorage.cs
- BulletChrome.cs
- SeverityFilter.cs
- WindowsProgressbar.cs
- SamlAttributeStatement.cs
- ActivityDesignerHighlighter.cs
- DocumentViewer.cs
- PenCursorManager.cs
- PropertyEmitterBase.cs
- infer.cs
- ContainerActivationHelper.cs
- SqlProfileProvider.cs
- StateMachineExecutionState.cs
- SimpleType.cs
- RequiredFieldValidator.cs
- StorageComplexTypeMapping.cs
- RuntimeConfigLKG.cs
- XamlHostingConfiguration.cs
- COM2PictureConverter.cs
- WebPartDisplayModeEventArgs.cs
- PageCodeDomTreeGenerator.cs
- WindowsListViewItemStartMenu.cs
- Timer.cs
- X509SecurityToken.cs
- COMException.cs
- MemberDescriptor.cs
- LinqExpressionNormalizer.cs
- PropertySegmentSerializer.cs
- WebPartConnectVerb.cs
- SchemaImporter.cs
- SizeAnimationUsingKeyFrames.cs
- WebPartUtil.cs
- CodeSnippetTypeMember.cs
- DataTransferEventArgs.cs
- RuntimeHandles.cs
- AxHostDesigner.cs
- DataGridRow.cs
- SettingsPropertyIsReadOnlyException.cs
- AsyncOperationContext.cs
- SqlDataSourceEnumerator.cs
- MruCache.cs
- ConcurrentDictionary.cs
- StoreAnnotationsMap.cs
- OpCodes.cs
- ComponentResourceManager.cs
- SmiRequestExecutor.cs
- PreviewKeyDownEventArgs.cs
- ProfilePropertyNameValidator.cs
- WorkflowMessageEventHandler.cs
- RectangleConverter.cs
- GlobalizationAssembly.cs
- IssuedSecurityTokenParameters.cs
- KeySpline.cs
- OleDbMetaDataFactory.cs
- DecimalAnimationUsingKeyFrames.cs
- LookupNode.cs
- PointLightBase.cs
- CodeMethodInvokeExpression.cs
- WebDisplayNameAttribute.cs
- MenuEventArgs.cs
- DeviceSpecificChoiceCollection.cs
- DateTimeOffset.cs
- MimeWriter.cs
- CompilationSection.cs
- ProviderConnectionPointCollection.cs
- OleDbConnectionInternal.cs
- RoutingConfiguration.cs
- WindowsMenu.cs