Recommendation 139: Event handler naming takes a combined approach
The so-called event handler is the method that is actually commissioned. See the following code:
PublicMainWindow () {InitializeComponent (); Button Button=NewButton (); button. Click+=Button_Click; button. SizeChanged+=button_sizechanged; button. MouseDown+=Button_mousedown; } voidButton_Click (Objectsender, EventArgs e) { Throw Newnotimplementedexception (); } voidButton_sizechanged (Objectsender, EventArgs e) { Throw Newnotimplementedexception (); } voidButton_mousedown (Objectsender, MouseEventArgs e) { Throw Newnotimplementedexception (); }
In this code, the methods Button_Click, button_sizechanged, Button_mousedown are called event handlers. vs defaults to the naming rules for the event handlers we generate:
Event variable owning object + underscore + Event variable name
This named method is used to register the method (the "+ =" operator) to add the event handler. If we are writing a processor for a callback in a delegate or delegate, you should use the following naming convention:
Delegate variable owning object +on+ delegate variable name
As follows:
Public BOOL Nameonvalidatevalue (object value) { } publicvoid Nameonpropertychanged (DependencyObject D, DependencyPropertyChangedEventArgs e) { }
Name of the failure:
Public void namechanged (DependencyObject D, DependencyPropertyChangedEventArgs e) { }
This name should look more like a delegate or an event variable.
Of course, if the processor is inside the class, you can omit the previous type and prefix it directly with on.
Turn from: 157 recommendations for writing high-quality code to improve C # programs Minjia
Go to write high-quality Code 157 recommendations for improving C # Programs--Recommendation 139: Event handler naming takes combination