简体   繁体   English

是否可以监视内部类中的更改?

[英]Is it possible to monitor changes in an internal class?

I'm using CSScript to load C# files as scripts at run-time. 我正在使用CSScript在运行时将C#文件作为脚本加载。 These scripts inherit from classes inside the host application. 这些脚本从主机应用程序内的类继承。 For faster loading I'm caching the scripts, or rather the compiled assemblies, and load those instead if they're newer than the script file. 为了更快地加载,我将缓存脚本或更确切地说是已编译的程序集,如果它们比脚本文件新,则将其加载。

Now, if a method inside the host application changes, the script naturally has to be recompiled, otherwise you get an exception, because the calls in the child don't match the parent anymore. 现在,如果宿主应用程序中的方法发生更改,则自然必须重新编译脚本,否则您将获得异常,因为子级中的调用不再与父级匹配。 But I don't want to recompile every script every time I recompile the application, because most of the time the changes aren't related to the script base classes. 但是我不想每次重新编译应用程序时都重新编译每个脚本,因为在大多数情况下,更改与脚本基类无关。

Is it possible to create a kind of "snapshot" of the methods in the base classes, their methods and arguments, during run-time (reflection?), to be able to tell when something changed, so I know I have to recompile the scripts? 是否有可能在运行时(反射?)在基类,其方法和参数中创建一种方法的“快照”,以便能够告知何时发生了更改,所以我知道我必须重新编译脚本?

Calculate hash values for your script files and compare them when loading. 计算脚本文件的哈希值,并在加载时进行比较。 If the hash value has changed, then the script file has been modified. 如果哈希值已更改,则说明脚本文件已被修改。

See https://support.microsoft.com/en-gb/kb/307020 请参阅https://support.microsoft.com/en-gb/kb/307020

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM