/// <summary>
 /// Converts a value to a <see cref="ConnectionStringSettings"/> object.
 /// </summary>
 public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
 {
     if (value is string)
     {
         ConnectionStringsSection section = ConnectionSettingsInfo.GetSection((EnvDTE.DTE)context.GetService(typeof(EnvDTE.DTE)));
         if (section != null)
         {
             return(section.ConnectionStrings[(string)value]);
         }
     }
     return(null);
 }
        /// <summary>
        /// Provides the list of valid values to choose from for the connection string.
        /// </summary>
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            ConnectionStringsSection section = null;

            if (String.IsNullOrEmpty(configurationArgument))
            {
                EnvDTE.DTE vs = (EnvDTE.DTE)context.GetService(typeof(EnvDTE.DTE));
                if (vs == null)
                {
                    return(new StandardValuesCollection(null));
                }
                EnvDTE.Project project = DteHelper.GetSelectedProject(vs);
                if (project == null)
                {
                    return(new StandardValuesCollection(null));
                }
                section = ConnectionSettingsInfo.GetSection(vs);
            }
            else
            {
                IDictionaryService dictionary        = (IDictionaryService)context.GetService(typeof(IDictionaryService));
                EnvDTE.ProjectItem configurationItem = dictionary.GetValue(configurationArgument) as EnvDTE.ProjectItem;
                if (configurationItem != null)
                {
                    section = ConnectionSettingsInfo.GetSection(configurationItem.get_FileNames(1));
                }
            }

            if (section == null)
            {
                return(new StandardValuesCollection(null));
            }

            List <ConnectionStringSettings> connectionslist = new List <ConnectionStringSettings>(section.ConnectionStrings.Count);

            foreach (ConnectionStringSettings setting in section.ConnectionStrings)
            {
                connectionslist.Add(setting);
            }
            connectionslist.Sort(CompareConnectionStringSettings);
            return(new StandardValuesCollection(connectionslist));
        }
        /// <summary>
        /// Determines if the value received is valid according to the current application
        /// configuration file.
        /// </summary>
        public override bool IsValid(ITypeDescriptorContext context, object value)
        {
            if (value is ConnectionStringSettings)
            {
                return(true);
            }
            if (!(value is string))
            {
                return(false);
            }

            ConnectionStringsSection section = ConnectionSettingsInfo.GetSection((EnvDTE.DTE)context.GetService(typeof(EnvDTE.DTE)));

            if (section == null)
            {
                return(false);
            }
            else
            {
                return(section.ConnectionStrings[(string)value] != null);
            }
        }