Ejemplo n.º 1
0
        /// <summary>
        /// Determines whether a specified C# using directive can be removed.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="usingDirective">The using directive.</param>
        /// <returns><c>true</c> if the specified using directive can be removed; otherwise, <c>false</c>.</returns>
        /// <remarks>As long as the using is represented as a T4 import directive in the root file, it can be removed.</remarks>
        public bool CanRemoveUsing(IDocument document, IUsingDirective usingDirective)
        {
            TreeTextRange nameRange = GetNameRange(usingDirective);

            if (!nameRange.IsValid())
            {
                return(false);
            }

            IFile containingFile = usingDirective.GetContainingFile();

            if (containingFile == null)
            {
                return(false);
            }

            DocumentRange documentRange = containingFile.GetDocumentRange(nameRange);

            return(documentRange.IsValid() && documentRange.Document == document);

//			IReferenceName namespaceNode = usingDirective.GetUsedNamespaceNode();
//			if (namespaceNode == null)
//				return false;
//
//			var directive = namespaceNode.GetT4ContainerFromCSharpNode<IT4Directive>();
//			return directive != null && directive.GetContainingNode<IT4Include>() == null;
        }
        /// <summary>Determines whether a specified C# using directive can be removed.</summary>
        /// <param name="document">The document.</param>
        /// <param name="usingDirective">The using directive.</param>
        /// <returns><c>true</c> if the specified using directive can be removed; otherwise, <c>false</c>.</returns>
        /// <remarks>As long as the using is represented as a T4 import directive in the root file, it can be removed.</remarks>
        public bool CanRemoveUsing(IDocument document, IUsingDirective usingDirective)
        {
            var nameRange = GetNameRange(usingDirective);

            if (!nameRange.IsValid())
            {
                return(false);
            }

            var containingFile = usingDirective.GetContainingFile();

            if (containingFile == null)
            {
                return(false);
            }

            var documentRange = containingFile.GetDocumentRange(nameRange);

            return(documentRange.IsValid() && documentRange.Document == document);
        }