Click here to Skip to main content
15,888,454 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Property Change Notifications Pin
Brisingr Aerowing27-Mar-15 6:54
professionalBrisingr Aerowing27-Mar-15 6:54 
GeneralRe: Property Change Notifications Pin
PIEBALDconsult27-Mar-15 7:28
mvePIEBALDconsult27-Mar-15 7:28 
GeneralRe: Property Change Notifications Pin
phil.o27-Mar-15 10:19
professionalphil.o27-Mar-15 10:19 
GeneralRe: Property Change Notifications Pin
Eddy Vluggen27-Mar-15 10:43
professionalEddy Vluggen27-Mar-15 10:43 
GeneralRe: Property Change Notifications Pin
Rob Grainger3-Apr-15 0:39
Rob Grainger3-Apr-15 0:39 
GeneralRe: Property Change Notifications Pin
Sander Rossel28-Mar-15 13:51
professionalSander Rossel28-Mar-15 13:51 
GeneralRe: Property Change Notifications Pin
Slacker0077-Apr-15 7:46
professionalSlacker0077-Apr-15 7:46 
GeneralRe: Property Change Notifications Pin
Rob Grainger7-Apr-15 22:28
Rob Grainger7-Apr-15 22:28 
In our code, it is all done via our own MVVM framework.

I have a SetProperty method defined on a base class, using a [CallerMemberName] argument to specify the property, which performs the following actions:
  1. If the value has not changed, exit immediately.
  2. Use Reflection to check the property specified actually exists.
  3. Call a method RaisePropertyChange to raise the event.
RaisePropertyChange is designed to allow firing notifications on derived properties when a base property or other change occurs that would affect their value (similar to most MVVM frameworks). Effectively this just triggers the PropertyChanged event, passing a property name as a string.

Note however that (perhaps unwisely) I didn't use reflection in RaisePropertyChange to check the property exists. The dev in question simply called this method, passing a string that doesn't correspond to a property name. I guess I didn't consider the probability of someone being that daft.

(I've now added the code to check - shame as it decreases the efficiency somewhat as it has to use Reflection to check each property access, but it costs to defend against stupidity. I'm just glad all this is in a managed language, I dread to think what would happen if these muppets were let loose on C++).
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.

GeneralSOMEONE had too much time on their hands... PinPopular
Brisingr Aerowing23-Mar-15 15:41
professionalBrisingr Aerowing23-Mar-15 15:41 
GeneralRe: SOMEONE had too much time on their hands... Pin
Afzaal Ahmad Zeeshan23-Mar-15 16:04
professionalAfzaal Ahmad Zeeshan23-Mar-15 16:04 
GeneralRe: SOMEONE had too much time on their hands... Pin
Sander Rossel23-Mar-15 21:26
professionalSander Rossel23-Mar-15 21:26 
GeneralRe: SOMEONE had too much time on their hands... Pin
Marc Clifton9-Apr-15 14:33
mvaMarc Clifton9-Apr-15 14:33 
GeneralOne enum to rule them all... Pin
Duncan Edwards Jones20-Mar-15 0:43
professionalDuncan Edwards Jones20-Mar-15 0:43 
GeneralRe: One enum to rule them all... Pin
den2k8820-Mar-15 0:50
professionalden2k8820-Mar-15 0:50 
GeneralRe: One enum to rule them all... Pin
OriginalGriff20-Mar-15 0:54
mveOriginalGriff20-Mar-15 0:54 
GeneralRe: One enum to rule them all... Pin
den2k8820-Mar-15 1:14
professionalden2k8820-Mar-15 1:14 
GeneralRe: One enum to rule them all... Pin
Afzaal Ahmad Zeeshan20-Mar-15 1:21
professionalAfzaal Ahmad Zeeshan20-Mar-15 1:21 
GeneralRe: One enum to rule them all... Pin
OriginalGriff20-Mar-15 1:25
mveOriginalGriff20-Mar-15 1:25 
GeneralRe: One enum to rule them all... Pin
den2k8820-Mar-15 1:30
professionalden2k8820-Mar-15 1:30 
GeneralRe: One enum to rule them all... Pin
Afzaal Ahmad Zeeshan20-Mar-15 1:31
professionalAfzaal Ahmad Zeeshan20-Mar-15 1:31 
GeneralRe: One enum to rule them all... Pin
Sander Rossel23-Mar-15 21:29
professionalSander Rossel23-Mar-15 21:29 
GeneralRe: One enum to rule them all... Pin
CDP180226-Mar-15 2:22
CDP180226-Mar-15 2:22 
GeneralRe: One enum to rule them all... Pin
phil.o20-Mar-15 1:10
professionalphil.o20-Mar-15 1:10 
GeneralRe: One enum to rule them all... Pin
kmoorevs21-Mar-15 8:02
kmoorevs21-Mar-15 8:02 
GeneralRe: One enum to rule them all... Pin
Nagy Vilmos26-Mar-15 3:22
professionalNagy Vilmos26-Mar-15 3:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.