コード例 #1
0
        /// <summary>
        /// Get all <see cref="TypeDecl"/>s declared in the <see cref="NamespaceDecl"/>, or
        /// in any nested NamespaceDecls (recursively).
        /// </summary>
        /// <param name="recursive">True to recursively look in child NamespaceDecls, otherwise false.</param>
        /// <param name="includeNestedTypes">True to include nested types, otherwise false.</param>
        public IEnumerable <TypeDecl> GetTypeDecls(bool recursive, bool includeNestedTypes)
        {
            if (_body != null)
            {
                foreach (CodeObject codeObject in _body)
                {
                    if (codeObject is NamespaceDecl && recursive)
                    {
                        foreach (TypeDecl typeDecl in ((NamespaceDecl)codeObject).GetTypeDecls(true, includeNestedTypes))
                        {
                            yield return(typeDecl);
                        }
                    }
                    else if (codeObject is TypeDecl)
                    {
                        TypeDecl typeDecl = (TypeDecl)codeObject;
                        yield return(typeDecl);

                        if (includeNestedTypes)
                        {
                            foreach (TypeDecl nestedType in typeDecl.GetNestedTypeDecls(true, true))
                            {
                                yield return(nestedType);
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Get all nested type declarations of the <see cref="TypeDecl"/>.
        /// </summary>
        /// <param name="recursive">True to recursively return all nested type declarations, otherwise false.</param>
        /// <param name="currentPartOnly">True to get nested types from current part only if the TypeDecl is partial, otherwise false.</param>
        public IEnumerable <TypeDecl> GetNestedTypeDecls(bool recursive, bool currentPartOnly)
        {
            if (_body != null)
            {
                foreach (CodeObject codeObject in _body)
                {
                    if (codeObject is TypeDecl)
                    {
                        TypeDecl typeDecl = (TypeDecl)codeObject;
                        yield return(typeDecl);

                        if (recursive)
                        {
                            foreach (TypeDecl nestedType in typeDecl.GetNestedTypeDecls(true, currentPartOnly))
                            {
                                yield return(nestedType);
                            }
                        }
                    }
                }
            }
            if (IsPartial && !currentPartOnly)
            {
                foreach (TypeDecl otherPart in GetOtherParts())
                {
                    if (otherPart.Body != null)
                    {
                        foreach (CodeObject codeObject in otherPart.Body)
                        {
                            if (codeObject is TypeDecl)
                            {
                                TypeDecl typeDecl = (TypeDecl)codeObject;
                                yield return(typeDecl);

                                if (recursive)
                                {
                                    foreach (TypeDecl nestedType in typeDecl.GetNestedTypeDecls(true))
                                    {
                                        yield return(nestedType);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }