The Labs \ Source Viewer \ SSCLI \ System.Configuration \ ConnectionStringSettings

  1. //------------------------------------------------------------------------------
  2. // <copyright file="ConnectionStringSettings.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. namespace System.Configuration
  16. {
  17.     using System;
  18.     using System.Xml;
  19.     using System.Configuration;
  20.     using System.Collections.Specialized;
  21.     using System.Collections;
  22.     using System.IO;
  23.     using System.Text;
  24.    
  25.     public sealed class ConnectionStringSettings : ConfigurationElement
  26.     {
  27.         private static ConfigurationPropertyCollection _properties;
  28.         private static readonly ConfigurationProperty _propName = new ConfigurationProperty("name", typeof(string), null, null, ConfigurationProperty.NonEmptyStringValidator, ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey);
  29.         private static readonly ConfigurationProperty _propConnectionString = new ConfigurationProperty("connectionString", typeof(string), "", ConfigurationPropertyOptions.IsRequired);
  30.         private static readonly ConfigurationProperty _propProviderName = new ConfigurationProperty("providerName", typeof(string), String.Empty, ConfigurationPropertyOptions.None);
  31.        
  32.         static ConnectionStringSettings()
  33.         {
  34.             // Property initialization
  35.             _properties = new ConfigurationPropertyCollection();
  36.             _properties.Add(_propName);
  37.             _properties.Add(_propConnectionString);
  38.             _properties.Add(_propProviderName);
  39.         }
  40.         public ConnectionStringSettings()
  41.         {
  42.         }
  43.        
  44.         public ConnectionStringSettings(string name, string connectionString) : this()
  45.         {
  46.             Name = name;
  47.             ConnectionString = connectionString;
  48.             // ProviderName = (string) _propProviderName.DefaultValue;
  49.         }
  50.        
  51.         public ConnectionStringSettings(string name, string connectionString, string providerName) : this()
  52.         {
  53.             Name = name;
  54.             ConnectionString = connectionString;
  55.             ProviderName = providerName;
  56.         }
  57.        
  58.         internal string Key {
  59.             get { return Name; }
  60.         }
  61.        
  62.         protected internal override ConfigurationPropertyCollection Properties {
  63.             get { return _properties; }
  64.         }
  65.        
  66.         [ConfigurationProperty("name", Options = ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey, DefaultValue = "")]
  67.         public string Name {
  68.             get { return (string)base[_propName]; }
  69.             set { base[_propName] = value; }
  70.         }
  71.        
  72.         [ConfigurationProperty("connectionString", Options = ConfigurationPropertyOptions.IsRequired, DefaultValue = "")]
  73.         public string ConnectionString {
  74.             get { return (string)base[_propConnectionString]; }
  75.             set { base[_propConnectionString] = value; }
  76.         }
  77.        
  78.         public override string ToString()
  79.         {
  80.             return ConnectionString;
  81.         }
  82.        
  83.         [ConfigurationProperty("providerName", DefaultValue = "System.Data.SqlClient")]
  84.         public string ProviderName {
  85.             get { return (string)base[_propProviderName]; }
  86.             set { base[_propProviderName] = value; }
  87.         }
  88.        
  89.     }
  90.     // class ConnectionStringSettings
  91. }

Developer Fusion