How to access a protected method in C#

Jasper picture Jasper · Dec 4, 2011 · Viewed 7.6k times · Source

I would like to know how to access a protected method.

I have a WebBrowser Control (Awesomium) which has many protected methods.

I created a Tabbed Browser with this WebControl in a WinForm.

Now I can't use ie InjectKeyboard-method cause it's protected.

This is the method:

//     Injects a keyboard event.
//
// Parameter:
//   keyEvent:
//     The keyboard event to inject. You'll need to initialize the members of the
//     passed Awesomium.Core.WebKeyboardEvent, yourself.
//
// Note:
//      Awesomium.Windows.Forms.WebControl handles this internally. Inheritors do
//     not need to call this method unless they implement custom logic.  This method
//     bypasses settings of the Awesomium.Windows.Forms.WebControl.InputController.
//      For performance reasons, no validity check is performed when calling protected
//     members.  Inheritors should perform any such checks (see Awesomium.Windows.Forms.WebControl.IsLive),
//     before calling these members.

protected void InjectKeyboardEvent(WebKeyboardEvent keyEvent);

While in the API Link is HERE

Why did they protect this method and how can I use it?

Answer

Matten picture Matten · Dec 4, 2011

Inherit from this class and expose the method if you need to (as proposed by the comment above the method).