private void LoadFileIntoModule(PSModuleInfo moduleInfo, Path path) { // prevents accidental loops while loading a module moduleInfo.NestingDepth++; if (moduleInfo.NestingDepth > 10) { var msg = "The module is too deeply nested. A module can be only nested 10 times. Make sure to check" + " the loading order of your module"; throw new PSInvalidOperationException(msg, "Modules_ModuleTooDeeplyNested", ErrorCategory.InvalidOperation); } moduleInfo.Path = path; // update path for nested modules var stringComparer = StringComparer.InvariantCultureIgnoreCase; var ext = path.GetExtension(); if (_scriptExtensions.Contains(ext, stringComparer)) { moduleInfo.ModuleType = ModuleType.Script; LoadScriptModule(moduleInfo, path); // actually load the script } else if (_binaryExtensions.Contains(ext, stringComparer)) { moduleInfo.ModuleType = ModuleType.Binary; LoadBinaryModule(moduleInfo, path); } else if (_manifestExtensions.Contains(ext, stringComparer)) { moduleInfo.ModuleType = ModuleType.Manifest; LoadManifestModule(moduleInfo, path); } else { var msg = "The extension '" + ext + "' is currently not supported"; throw new PSInvalidOperationException(msg, "Modules_InvalidFileExtension", ErrorCategory.InvalidOperation, null, false); } moduleInfo.ValidateExportedMembers(); }