【发布时间】:2012-06-07 07:37:57
【问题描述】:
我有一个在 Windows 中运行良好的 DLL,但在它的一个私有函数中调用了静态 System.IO.File.ReadAllBytes()。我必须在带有 Compact Framework 3.5 的 Windows CE 智能设备项目上使用此 DLL,并且 System.IO.File 中没有这种方法。我试图在项目中创建一个名为“File”的类,如下所示:
public class File
{
internal static byte[] ReadAllBytes(string path)
{
}
internal static void WriteAllBytes(string path, byte[] bytes)
{
}
}
我自己对 File 类的静态方法的调用被重定向到这里但是 DLL 方法内部的调用仍然转到 System.Io.File 类,我仍然得到 MissingMethodException。我尝试了使用公共修饰符的方法,但没有发现任何变化。
我什至尝试重写调用私有方法的公共方法,其中调用了 ReadAllbytes 并使用 MethodInfo.Invoke 没有成功。
问题:有没有办法强制 Dll 中的方法接受我的 ReadAllbytes 方法而不是 System.File.IO.ReadAllBytes()? DLL里面的调用是这样的:
using System.IO.File;
namespace Something
{
class SomeClass
{
public Boolean someMethod()
{
byte[] myBytes = File.ReadAllBytes(filePath);
}
}
}
【问题讨论】:
-
不能简单的把DLL的代码改一下重新编译吗?
标签: c# reflection replace .net