使用一个接口,就从被标记为QUOT外部组件;内部" (C#) [英] Use an interface from an external assembly that's marked as "internal" (C#)
问题描述
我想实现驻留在外部组件的接口。但是,这种特定的接口已被标记为内部。有没有一种方法,我仍然可以实现此接口为我自己的类?
I'd like to implement an interface that resides in an external assembly. However that particular interface has been marked as "internal". Is there a way I can still implement this interface for my own classes?
我知道如何调用使用反射在C#中的私人/内部方法,所以我想应该反思在这种情况下使用了。但是,我不知道怎么办。是的,我知道它通常是不明智的使用内部/私有的东西,但在这种情况下,我没有看到其他的解决方案。
I know how to call private/internal methods using reflection in C#, so I guess reflection should be used in this case too. However, I don't know how. And yes, I do know it usually isn't wise to use internal/private stuff, but in this case I see no other solution.
更新:我不能够编辑/更改外部组件以任何方式。应该保持不变。
Update: I'm not able to edit / change the external assembly in any way. It should be left untouched.
推荐答案
您不能这样做,除非你可以改变组件包含界面上添加一个<一个href="http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute.aspx"相对=nofollow> InternalsVisibleToAttribute ,针对自己的汇编。
You can't do that, unless you can change the assembly containing the interface to add an InternalsVisibleToAttribute, targeting your own assembly.
这篇关于使用一个接口,就从被标记为QUOT外部组件;内部&QUOT; (C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!