示例#1
0
        /// <summary>
        /// Determines whether the specified attribute has a property with the specified value.
        /// </summary>
        /// <param name="attributeFullName">Full name of the attribute.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="propertyValue">The property value.</param>
        /// <returns>
        ///     <c>true</c> if the attribute property has the specified value; otherwise, <c>false</c>.
        /// </returns>
        public bool HasAttributePropertyValue(string attributeFullName, string propertyName, object propertyValue)
        {
            if (HasAttribute(attributeFullName))
            {
                return(InternalHasAttributePropertyValue((CodeElement)codeType, attributeFullName, propertyName, propertyValue));
            }

            CodeElement element = FileCodeModelHelper.FindCodeElementFromType((CodeElement)codeType, attributeFullName, vsCMElement.vsCMElementAttribute);

            if (element != null)
            {
                return(InternalHasAttributePropertyValue(element, attributeFullName, propertyName, propertyValue));
            }

            return(false);
        }
示例#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         vs   = GetService <DTE>();
            ProjectItem item = vs.ActiveDocument.ProjectItem;

            newValue = null;

            if (item != null && item.FileCodeModel != null)
            {
                newValue = FileCodeModelHelper.GetCodeElement(vs, item.FileCodeModel, this.Argument.Type);

                return(true);
            }

            return(false);
        }
示例#3
0
        private bool Evaluate(out object newValue)
        {
            newValue = null;
            string typeName = ExpressionEvaluationHelper.EvaluateExpression((IDictionaryService)GetService(typeof(IDictionaryService)),
                                                                            TypeNameExpression) as string;
            Project project = ExpressionEvaluationHelper.EvaluateExpression((IDictionaryService)GetService(typeof(IDictionaryService)),
                                                                            ProjectExpression) as Project;

            if (typeName != null && project != null)
            {
                CodeClass targetClass = FileCodeModelHelper.FindCodeElementFromType(project, typeName, vsCMElement.vsCMElementClass) as CodeClass;
                newValue = (targetClass != null);
                return(true);
            }

            return(false);
        }
示例#4
0
        /// <summary>
        /// Performs the validation of the item passed as target
        /// Returns true if the reference is allowed to be executed in the target
        /// that is if the target is the CodeElement specified in the CodeElementTypeName property.
        /// </summary>
        /// <param name="target"></param>
        /// <returns></returns>
        public override bool IsEnabledFor(object target)
        {
            DTE vs = GetService <DTE>();

            if (vs == null || vs.ActiveDocument == null)
            {
                return(false);
            }

            ProjectItem            item = vs.ActiveDocument.ProjectItem;
            ITypeResolutionService typeResolutionService = GetService <ITypeResolutionService>();

            if (item != null && item.FileCodeModel != null)
            {
                object element = FileCodeModelHelper.GetCodeElement(vs, item.FileCodeModel, typeResolutionService.GetType(codeElementTypeName));
                return(element != null);
            }

            return(false);
        }