Comment accéder à une méthode protégée en C #
-
28-10-2019 - |
Question
Je voudrais savoir comment accéder à une méthode protégée.
J'ai un contrôle WebBrowser (Awesomium) qui a de nombreuses méthodes protégées.
Je créé un navigateur à onglets avec ce WebControl dans un WinForm.
Maintenant, je ne peux pas utiliser par exemple InjectKeyboard
méthode parce que c'est protégé.
Ceci est la méthode:
// 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);
Pourquoi ont-ils protéger cette méthode et comment puis-je utiliser?
La solution
Hériter de cette classe et d'exposer la méthode si vous devez (tel que proposé par le commentaire ci-dessus la méthode).
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow