Exemple #1
0
        /// <summary>
        /// Get valid module files from module paths.
        /// </summary>
        private IEnumerable <string> GetValidModuleFiles(HashSet <string> moduleNamesToFind)
        {
            var modulePaths = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (string path in ModuleIntrinsics.GetModulePath(includeSystemModulePath: false, Context))
            {
                string uniquePath = path.TrimEnd(Utils.Separators.Directory);
                if (!modulePaths.Add(uniquePath))
                {
                    continue;
                }

                foreach (string moduleFile in ModuleUtils.GetDefaultAvailableModuleFiles(uniquePath))
                {
                    // We only care about module manifest files because that's where experimental features are declared.
                    if (!moduleFile.EndsWith(StringLiterals.PowerShellDataFileExtension, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    if (moduleNamesToFind != null)
                    {
                        string currentModuleName = ModuleIntrinsics.GetModuleName(moduleFile);
                        if (!moduleNamesToFind.Contains(currentModuleName))
                        {
                            continue;
                        }
                    }

                    yield return(moduleFile);
                }
            }
        }
Exemple #2
0
        private bool FindTypeByModulePath(WildcardPattern classNameMatcher)
        {
            bool matchFound = false;

            var moduleList = ModuleUtils.GetDefaultAvailableModuleFiles(isForAutoDiscovery: false, _context);

            foreach (var modulePath in moduleList)
            {
                string expandedModulePath = IO.Path.GetFullPath(modulePath);
                var    cachedClasses      = AnalysisCache.GetExportedClasses(expandedModulePath, _context);

                if (cachedClasses != null)
                {
                    //Exact match
                    if (!_useWildCards)
                    {
                        if (cachedClasses.ContainsKey(_className))
                        {
                            var classInfo = CachedItemToPSClassInfo(classNameMatcher, modulePath);
                            if (classInfo != null)
                            {
                                _matchingClassList.Add(classInfo);
                                matchFound = true;
                            }
                        }
                    }
                    else
                    {
                        foreach (var className in cachedClasses.Keys)
                        {
                            if (classNameMatcher.IsMatch(className))
                            {
                                var classInfo = CachedItemToPSClassInfo(classNameMatcher, modulePath);
                                if (classInfo != null)
                                {
                                    _matchingClassList.Add(classInfo);
                                    matchFound = true;
                                }
                            }
                        }
                    }
                }
            }

            return(matchFound);
        }