How to override an internal function

寵の児 提交于 2020-01-07 02:51:13

问题


How can i override a virtual internal function using reflection?

I have an abstract class in a sharepoint assembly (SPIisWebServiceApplication) that i want to implement.

In my logic i'm obligated to override the IisApplicationName property that i can see it using reflector it is writen like below:

internal virtual string IisApplicationName { get { return base.Id.ToString("N"); } }

it is only internal it is not protected...

I don't want the IisApplicationName to be an id because it appears in the IIS. I want to override it as they have done in other internal implementers.


回答1:


Reflection is about accessing the structure of existing types, not changing it. (You can change the data stored in instances of types, but you can't change the structure of the type itself.)

It's not clear what you're trying to do, but reflection is unlikely to help you if you're trying to override a member.




回答2:


You can derive from the class normally and override the function, which is presumably protected virtual internal (private cannot be virtual, and it would not need to be internal if it were public). Such an access specification allows the access model of both interal and protected -- i.e., the method can be accessed from classes in the same assembly and from derived classes.

Is there something that prevents you from doing this?



来源:https://stackoverflow.com/questions/5430622/how-to-override-an-internal-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!