Gaby
Gaby

Reputation: 3033

How to override an internal function

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.

Upvotes: 0

Views: 3063

Answers (2)

Jon
Jon

Reputation: 437544

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?

Upvotes: 1

Jon Skeet
Jon Skeet

Reputation: 1502076

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.

Upvotes: 6

Related Questions