How it works...
Pre-event and post-event handlers work in the same way as the other event handlers, but these carry a risk of regression. The events we handle through this technique are not delegates, and the developer did not specifically write the method to be handled in this way: otherwise they would have written a delegate. The reason we are restricted to public methods is because these are considered as a public API, and will not be changed or deprecated without a proper procedure. Protected methods can be changed without warning, and we could, therefore, find that our code no longer works.
Private methods are private for a reason: you can't guarantee the internal class state, or how these will be called.
This also reinforces that we ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access