简体   繁体   English

检测调用者是否可以访问我的程序集内部

[英]Detect if the caller has access to my assembly internals

I need to detect in a method if its caller has internal access to my assembly. 我需要在一个方法中检测其调用者是否对我的程序集具有内部访问权限。 That is, if it is a) code in the same assembly or b) has a InternalsVisibleTo relationship with my assembly. 也就是说,如果是a)在同一程序集中的代码或b)与我的程序集具有InternalsVisibleTo关系。 Ideally the check should be fast. 理想情况下,检查应该很快。

What are my options? 我有什么选择?

UPDATE: I would also be partially satisfied if there was a good solution for part a of the problem. 更新:如果对问题的a部分有一个好的解决方案,我也会部分满意。

Look into System.Diagnostics.StackTrace 研究System.Diagnostics.StackTrace

    System.Diagnostics.StackTrace st = new StackTrace();
    MethodBase mb = st.GetFrame(1).GetMethod();
    Assembly a = mb.DeclaringType.Assembly;

a) just compare current assembly to a a)只是将当前程序集与a

b) i think you should be able to pick out the InternalsVisibleTo attributes on the assembly b)我认为您应该能够在程序集中选择InternalsVisibleTo属性

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

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