示例#1
0
文件: Utils.cs 项目: sarvex/StyleCop
        /// <summary>
        /// Returns true if we're inside one of the container types..
        /// </summary>
        /// <param name="expresion">
        /// The expression to start at.
        /// </param>
        /// <param name="codeUnits">
        /// The containers to check.
        /// </param>
        /// <returns>
        /// True if found.
        /// </returns>
        public static bool IsExpressionInsideContainer(Expression expresion, params Type[] codeUnits)
        {
            ICodePart parent = expresion.Parent;

            while (parent != null)
            {
                foreach (Type codeUnit in codeUnits)
                {
                    if (parent.GetType() == codeUnit)
                    {
                        return(true);
                    }
                }

                parent = parent.Parent;
            }

            return(false);
        }
        public void Register(ICodePart child, ICodePart parent = null)
        {
            if (parent != null)
            {
                Register(new ChildLink(parent, child));
            }
            switch (child)
            {
            case Solution solution:
                Solutions.TryAdd(solution.FullName, solution);
                solution.Projects.ForEach(p => Register(p, solution));
                break;

            case Project project:
                Projects.TryAdd(project.FullName, project);
                project.SourceFiles.Values.ForEach(c => Register(c, project));
                break;

            case SourceFile sourceFile:
                SourceFiles.TryAdd(sourceFile.FullName, sourceFile);
                sourceFile.Classes.Values.ForEach(c => Register(c, parent));
                sourceFile.Classes.Values.ForEach(c => Register(c, sourceFile));
                break;

            case Class cls:
                Classes.TryAdd(cls.FullName, cls);
                cls.Children.ForEach(c => Register(c, cls));
                cls.Implements.ForEach(interfaceName => Interfaces.TryAdd(interfaceName, cls));
                break;

            case Method method:
                Methods.TryAdd(method.FullName, method);
                break;

            case Property property:
                //TODO
                break;

            default:
                throw new NotSupportedException("Unknown code part: " + child.GetType());
            }
        }