Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new feature block with new type members.
        /// </summary>
        /// <param name="originalFile">The original T4 file where the feature block must be created.</param>
        /// <param name="text">The code representing new C# type members.</param>
        /// <param name="first">The first node.</param>
        /// <param name="last">The last node.</param>
        /// <returns>A <see cref="TreeTextRange"/> representing the code range in the newly created feature block.</returns>
        protected override TreeTextRange CreateTypeMemberNode(IFile originalFile, string text, ITreeNode first, ITreeNode last)
        {
            T4FeatureBlock featureBlock = T4ElementFactory.Instance.CreateFeatureBlock(text);

            featureBlock = ((IT4File)originalFile).AddFeatureBlock(featureBlock);
            return(featureBlock.GetCodeToken().GetTreeTextRange());
        }
        private static void ProcessT4FeatureBlock([NotNull] T4FeatureBlock featureBlock, [NotNull] CodeStructureElement parentElement,
                                                  [NotNull] ICSharpFile cSharpFile, [NotNull] ISecondaryRangeTranslator secondaryRangeTranslator, [NotNull] CSharpCodeStructureProcessingState state)
        {
            TreeTextRange t4Range     = featureBlock.GetCodeToken().GetTreeTextRange();
            TreeTextRange cSharpRange = secondaryRangeTranslator.OriginalToGenerated(t4Range);

            if (!cSharpRange.IsValid())
            {
                return;
            }

            TreeOffset cSharpStart = cSharpRange.StartOffset;
            TreeOffset cSharpEnd   = cSharpRange.EndOffset;

            ITreeNode containingNode = cSharpFile.FindNodeAt(cSharpRange);

            if (containingNode == null)
            {
                return;
            }

            for (ITreeNode node = containingNode.FirstChild; node != null; node = node.NextSibling)
            {
                TreeOffset nodeStart = node.GetTreeStartOffset();
                if (nodeStart >= cSharpStart && nodeStart < cSharpEnd)
                {
                    ProcessCSharpNode(node, parentElement, state);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets an existing feature block that can contains type members.
        /// </summary>
        /// <param name="originalFile">The original T4 file.</param>
        /// <returns>A valid <see cref="TreeTextRange"/> if a feature block existed, <see cref="TreeTextRange.InvalidRange"/> otherwise.</returns>
        protected override TreeTextRange GetExistingTypeMembersRange(IFile originalFile)
        {
            T4FeatureBlock lastFeatureBlock = ((IT4File)originalFile).GetFeatureBlocks().LastOrDefault();

            return(lastFeatureBlock == null
                                ? TreeTextRange.InvalidRange
                                : lastFeatureBlock.GetCodeToken().GetTreeTextRange());
        }