public virtual string ToDisplayString()
        {
            PropertyDescriptorCollection          sensitiveProperties = GetProperties(new Attribute[] { PasswordPropertyTextAttribute.Yes });
            List <KeyValuePair <string, object> > savedValues         = new List <KeyValuePair <string, object> >();

            foreach (PropertyDescriptor sensitiveProperty in sensitiveProperties)
            {
                string propertyName = sensitiveProperty.DisplayName;
                if (ConnectionStringBuilder.ShouldSerialize(propertyName))
                {
                    savedValues.Add(new KeyValuePair <string, object>(propertyName, ConnectionStringBuilder[propertyName]));
                    ConnectionStringBuilder.Remove(propertyName);
                }
            }
            try
            {
                return(ConnectionStringBuilder.ConnectionString);
            }
            finally
            {
                foreach (KeyValuePair <string, object> savedValue in savedValues)
                {
                    if (savedValue.Value != null)
                    {
                        ConnectionStringBuilder[savedValue.Key] = savedValue.Value;
                    }
                }
            }
        }
        public override string ToDisplayString()
        {
            string str2;
            var    properties = ((ICustomTypeDescriptor)this).GetProperties(new Attribute[] { PasswordPropertyTextAttribute.Yes });
            var    list       = new List <KeyValuePair <string, object> >();

            foreach (PropertyDescriptor descriptor in properties)
            {
                string str = descriptor.DisplayName;
                if (!ConnectionStringBuilder.ShouldSerialize(str))
                {
                    continue;
                }

                list.Add(new KeyValuePair <string, object>(str, ConnectionStringBuilder[str]));
                ConnectionStringBuilder.Remove(str);
            }
            try
            {
                str2 = ConnectionStringBuilder.ToString();
            }
            finally
            {
                foreach (KeyValuePair <string, object> pair in list)
                {
                    if (pair.Value != null)
                    {
                        ConnectionStringBuilder[pair.Key] = pair.Value;
                    }
                }
            }

            return(str2);
        }
Exemplo n.º 3
0
        public void CanDelete()
        {
            var updater = new ConnectionStringBuilder("User Id=blah; Password=blah2");

            updater.Remove("Password");

            Assert.AreEqual("user id=blah", updater.ConnectionString);
        }
        protected override string ToTestString()
        {
            bool savedPooling = (bool)ConnectionStringBuilder["Pooling"];
            bool wasDefault   = !ConnectionStringBuilder.ShouldSerialize("Pooling");

            ConnectionStringBuilder["Pooling"] = false;
            string testString = ConnectionStringBuilder.ConnectionString;

            ConnectionStringBuilder["Pooling"] = savedPooling;
            if (wasDefault)
            {
                ConnectionStringBuilder.Remove("Pooling");
            }
            return(testString);
        }
        public override string ToDisplayString()
        {
            string savedPassword = null;

            if (ConnectionStringBuilder.ContainsKey("Jet OLEDB:Database Password") &&
                ConnectionStringBuilder.ShouldSerialize("Jet OLEDB:Database Password"))
            {
                savedPassword = ConnectionStringBuilder["Jet OLEDB:Database Password"] as string;
                ConnectionStringBuilder.Remove("Jet OLEDB:Database Password");
            }
            string displayString = base.ToDisplayString();

            if (savedPassword != null)
            {
                ConnectionStringBuilder["Jet OLEDB:Database Password"] = savedPassword;
            }
            return(displayString);
        }