/// <summary>
        /// Returns whether the given value object is valid for this type and for the specified context.
        /// </summary>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context.</param>
        /// <param name="value">The <see cref="T:System.Object"></see> to test for validity.</param>
        /// <returns>
        /// true if the specified value is valid for this object; otherwise, false.
        /// </returns>
        public override bool IsValid(ITypeDescriptorContext context, object value)
        {
            bool response = true;

            if (value is string)
            {
                DTE vs = (DTE)context.GetService(typeof(DTE));
                response = !DteHelperEx.ProjectExists(vs.Solution, value.ToString(), this.language);
            }

            return(response);
        }
Esempio n. 2
0
        /// <summary>
        /// Contains code that will be called when recipe execution begins. This is the first method in the lifecycle.
        /// </summary>
        /// <param name="currentValue">An <see cref="T:System.Object"/> that contains the current value of the argument.</param>
        /// <param name="newValue">When this method returns, contains an <see cref="T:System.Object"/> that contains
        /// the new value of the argument, if the returned value
        /// of the method is <see langword="true"/>. Otherwise, it is ignored.</param>
        /// <returns>
        ///     <see langword="true"/> if the argument value should be replaced with
        /// the value in <paramref name="newValue"/>; otherwise, <see langword="false"/>.
        /// </returns>
        /// <remarks>By default, always returns <see langword="false"/>, unless overriden by a derived class.</remarks>
        public override bool OnBeginRecipe(object currentValue, out object newValue)
        {
            DTE dte = (DTE)GetService(typeof(DTE));

            ExpressionEvaluationService evaluator   = new ExpressionEvaluationService();
            IDictionaryService          dictservice = (IDictionaryService)GetService(typeof(IDictionaryService));

            string defaultName = evaluator.Evaluate(
                this.expression,
                new ServiceAdapterDictionary(dictservice)).ToString();

            string projectName = defaultName;

            while (DteHelperEx.ProjectExists(dte.Solution, projectName, this.language))
            {
                projectName = ProvideNewDefaultValue(defaultName, projectName);
            }

            newValue = projectName;
            return(true);
        }