Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# 3.0 Auto-Properties - Is it possible to add custom behaviour?

I would like to know if there is any way to add custom behaviour to the auto property get/set methods.

An obvious case I can think of is wanting every set property method to call on any PropertyChanged event handlers as part of a System.ComponentModel.INotifyPropertyChanged implementation. This would allow a class to have numerous properties that can be observed, where each property is defined using auto property syntax.

Basically I'm wondering if there is anything similar to either a get/set template or post get/set hook with class scope.

(I know the same end functionality can easily be achieved in slightly more verbose ways - I just hate duplication of a pattern)

like image 641
morechilli Avatar asked Sep 22 '08 17:09

morechilli


1 Answers

No, you'll have to use "traditional" property definitions for custom behavior.

like image 176
John Sheehan Avatar answered Oct 13 '22 22:10

John Sheehan