/// <summary>
        /// Returns the children of this statement that have the same name as the given <paramref name="use"/>, and the given type.
        /// This method searches only the immediate children, and not further descendants.
        /// If the <paramref name="use"/> occurs within this statement, this method will return only the children
        /// that occur prior to that use.
        /// </summary>
        /// <typeparam name="T">The type of children to return.</typeparam>
        /// <param name="use">The use containing the name to search for.</param>
        /// <param name="searchDeclarations">Whether to search the child DeclarationStatements for named entities.</param>
        public override IEnumerable <T> GetNamedChildren <T>(NameUse use, bool searchDeclarations)
        {
            var matches = base.GetNamedChildren <T>(use, searchDeclarations);

            //check if we should filter the results
            if (ChildStatements.Count > 0)
            {
                var firstTryLoc      = ChildStatements.First().PrimaryLocation;
                var lastTryLoc       = ChildStatements.Last().PrimaryLocation;
                var tryBlockLocation = new SourceLocation(firstTryLoc.SourceFileName, firstTryLoc.StartingLineNumber, firstTryLoc.StartingColumnNumber, lastTryLoc.EndingLineNumber, lastTryLoc.EndingColumnNumber);
                if (this.PrimaryLocation.Contains(use.Location) && !tryBlockLocation.Contains(use.Location))
                {
                    //the use is within the overall TryStatement, but not in the try block. Don't return results from the try block
                    return(matches.SkipWhile(m => tryBlockLocation.Contains(m.GetLocations().First())));
                }
            }
            return(matches);
        }
Example #2
0
        public override void RemoveFile(string fileName)
        {
            RemoveLocations(fileName);
            RemoveFileFromChildren(fileName);

            if (ToBeDeleted)
            {
                var orphanedChildren = (from child in ChildStatements.OfType <NamedScope>()
                                        where !child.ToBeDeleted && null != child.Prefix
                                        select child).ToList();

                foreach (var child in orphanedChildren)
                {
                    child.ResetPrefix();
                }
                ParentStatement = null;
            }
        }
 private MethodDefinition SearchForSetter()
 {
     return(ChildStatements.OfType <MethodDefinition>().FirstOrDefault(m => m.Name == "set"));
 }