Browse DevX
Sign up for e-mail newsletters from DevX


What's New in Visual Studio .NET 1.1? : Page 2

Visual Studio .NET provides a new set of features designed to improve and enhance the development experience. Most of these changes have to do with user ergonomics and are typical of a minor release of a Visual Studio product. Only a few of the changes are related to the underlying platform.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

C# Automatic Event Hookup and Handler Generation
.NET delegate-based events are a type safe way to connect an event publisher to an event subscriber. Because the exact signature of the event handling method is known, IntelliSense can generate the code creating a new delegate object targeting the event handling method, and even the event handling method itself.

For example, consider the MyPublisher class, which is used to publish events to interested subscribers about changes to the value of some number:

public delegate void NumberChanged(int num); public class MyPublisher { public event NumberChanged NumberChanged; /* Other methods and members */ }

Suppose the class MySubscriber wants to subscribe to the event in the class constructor. When you type the += operator to assign into a delegate, IntelliSense will preset a ToolTip offering to add a new delegate of a matching type by pressing the Tab key. If you do not like the default target method name you can simply type a different method name in its place. If the target method does not exist, IntelliSense will offer to generate a handling method by that name by pressing the Tab key once more. This sequence is presented in Figure 3. This IntelliSense support only works with delegates defined as events (not mere delegates). Also worth mentioning is that there is no IntelliSense support for removing a subscription:

public void UnSubscribe() { //This has no IntelliSense support: publisher.NumberChanged -= new NumberChanged(OnNumberChnaged); }

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date