Skip to content

Commit

Permalink
Remove unnecessary reflection in Environment.GetFolderPathCore.Unix.cs (
Browse files Browse the repository at this point in the history
#55677)

System.IO.Directory was moved into CoreLib with #53231 so we can call it directly now.
  • Loading branch information
akoeplinger authored Jul 15, 2021
1 parent bbcb6b7 commit 39135a4
Showing 1 changed file with 1 addition and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ namespace System
{
public static partial class Environment
{
private static Func<string, object>? s_directoryCreateDirectory;

private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOption option)
{
// Get the path for the SpecialFolder
Expand All @@ -40,16 +38,7 @@ private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOptio

Debug.Assert(option == SpecialFolderOption.Create);

Func<string, object>? createDirectory = Volatile.Read(ref s_directoryCreateDirectory);
if (createDirectory is null)
{
Type dirType = Type.GetType("System.IO.Directory, System.IO.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", throwOnError: true)!;
MethodInfo mi = dirType.GetMethod("CreateDirectory", BindingFlags.Public | BindingFlags.Static)!;
createDirectory = mi.CreateDelegate<Func<string, object>>();
Volatile.Write(ref s_directoryCreateDirectory, createDirectory);
}

createDirectory(path);
Directory.CreateDirectory(path);

return path;
}
Expand Down

0 comments on commit 39135a4

Please sign in to comment.