计算在运行时(C#)的类代码哈希? [英] Compute hash of class code at runtime (C#)?

查看:104
本文介绍了计算在运行时(C#)的类代码哈希?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能来计算类的哈希在C#(假设通过反射)运行?要清楚,我不想说,计算类的一个实例的哈希码,我想计算的类代码本身的哈希(如果在类变化的函数,我期待一个不同的散列码是计算)。理想情况下,这将仅是在目标代码的变化(而不仅仅是代码本身的字符串表示的哈希值)很敏感。

Is it possible to compute the hash of a class at runtime in C# (presumably through reflection)? To be clear, I don't want to compute the hashcode of an instance of said class, I want to compute the hash of the class code itself (if a function in the class changes, I'd expect a different hash code to be computed). Ideally this would only be sensitive to changes in the object code (and not just a hash of the string representation of the code itself).

在您的帮助谢谢,

- 布雷克

推荐答案

如果您有键入您可以使用 GetMethod 获得的MethodInfo ,这在反过来有一个 GetMethodBody ,返回的IL该方法。然后,您可以哈希说。

If you have the Type you can use GetMethod to get an instance of MethodInfo, which in turn has a GetMethodBody that returns the IL for said method. You can then hash that.

我很好奇。你为什么想做这个摆在首位?

I am curious. Why do you want to do this in the first place?

这篇关于计算在运行时(C#)的类代码哈希?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆