This project is read-only.

Autowired events

Topics: C# Language Design
Apr 7, 2014 at 1:19 AM
Edited Apr 9, 2014 at 4:20 PM

public class MyWindow {
    TreeView MyTree {get;set;}
    void MyTree.SelectionChanged(object sender, RoutedEventArgs e) {    }
}

The idea is to enhance some auto properties to do automatic event wiring to class methods. When property get value - event handlers are attached, when property is set null - handlers are detached.

There is a possibility of conflict with implicit interface implementations, which can be ruled in favor of interface or both, interface and event handler.

MyTree.SelectionChanged (with dot) is more desireable than MyTree_SelectionChanged (with underscore) because dot will indicate event handler and compiler can generate error if there is no property/event with specified names. It may also be easier for code completion to propose events list after typing a dot.