private static FileOpenDelegate GetFileOpenFunction()
{
Type fileSystemType = Type.GetType("System.IO.File, System.IO.FileSystem, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", throwOnError: false);
var methodInfos = fileSystemType?.GetTypeInfo().GetDeclaredMethods("Open");
if (methodInfos != null)
{
foreach (MethodInfo methodInfo in methodInfos)
{
var methodParams = methodInfo.GetParameters();
if (methodParams?.Length == 4 &&
methodParams[0].Name == "path" &&
methodParams[1].Name == "mode" &&
methodParams[2].Name == "access" &&
methodParams[3].Name == "share")
{
return (FileOpenDelegate)methodInfo.CreateDelegate(typeof(FileOpenDelegate));
}
}
}
Debug.Fail("Could not access the File.Open function via reflection into System.IO.FileSystem version 4.0.1.0.");
return null;
}
}