Replace custom method with File.ReadAllText() in ScriptAnalysis.cs (#26060)

This commit is contained in:
Amrit Anand
2025-10-15 16:36:24 +00:00
committed by GitHub
parent 47e38beda5
commit b77c80ec2f
2 changed files with 2 additions and 15 deletions
@@ -40,7 +40,7 @@ namespace System.Management.Automation
// So eat the invalid operation
}
string scriptContent = ReadScript(path);
string scriptContent = File.ReadAllText(path, Encoding.Default);
ParseError[] errors;
var moduleAst = (new Parser()).Parse(path, scriptContent, null, out errors, ParseMode.ModuleAnalysis);
@@ -89,19 +89,6 @@ namespace System.Management.Automation
return result;
}
internal static string ReadScript(string path)
{
using (FileStream readerStream = new FileStream(path, FileMode.Open, FileAccess.Read))
{
Microsoft.Win32.SafeHandles.SafeFileHandle safeFileHandle = readerStream.SafeFileHandle;
using (StreamReader scriptReader = new StreamReader(readerStream, Encoding.Default))
{
return scriptReader.ReadToEnd();
}
}
}
internal List<string> DiscoveredExports { get; set; }
internal Dictionary<string, string> DiscoveredAliases { get; set; }
@@ -340,7 +340,7 @@ namespace System.Management.Automation
internal static Hashtable GetModuleManifestProperties(string psDataFilePath, string[] keys)
{
string dataFileContents = ScriptAnalysis.ReadScript(psDataFilePath);
string dataFileContents = File.ReadAllText(psDataFilePath, Encoding.Default);
ParseError[] parseErrors;
var ast = (new Parser()).Parse(psDataFilePath, dataFileContents, null, out parseErrors, ParseMode.ModuleAnalysis);
if (parseErrors.Length > 0)