Re: Lots of bind/notify classes
Hi Greg, I hear your pain and reflect it. You could probably set up a method using PostSharp to automatically create the necessary setter code, but that's provided you can introduce PostSharp into your process. The best I've managed is to set up a Visual Studio code snippet to help create them quickly. I deferred doing that for a long time, but recently got around to it and it does make things much less painful. But unfortunately still far from ideal. Just grab the existing 'prop' code snippet and expand it out from there. 'tis fairly simple to do and well worth the effort. ciao, Richard On Fri, May 28, 2010 at 4:18 PM, Greg Keogh g...@mira.net wrote: *Look Dave, I can see you're really upset about this. I honestly think you ought to sit down calmly, take a stress pill, and think things over* – HAL (2001) I was wondering if anyone has found a nice way of creating/managing lots of classes that are suitable for binding and implement INotifyPropertyChanged. As you know, you have to keep coding properties like this: public string CompanyName { get {return this.companyNameValue;} set { if (value != this.companyNameValue) { this.companyNameValue = value; NotifyPropertyChanged(CompanyName); } } } You can create a simple base class to factor out the event, but not much else, as there is no way I know of to intercept any arbitrary property setter and add custom processing. Is that right?! Coding the above skeleton dozens or hundreds of times gets tedious and I’m hoping there’s a better way. I did consider using a T4 generator to spit out the classes, but that’s an obtuse way around the problem and will require extra research time (but I see others have done it already). I have dozens of existing classes with dozens of properties and I’d like to use them for binding, but I’d have to expand every property to be like the same above, which would be hell. Greg ___ ozsilverlight mailing list ozsilverlight@ozsilverlight.com http://prdlxvm0001.codify.net/mailman/listinfo/ozsilverlight ___ ozsilverlight mailing list ozsilverlight@ozsilverlight.com http://prdlxvm0001.codify.net/mailman/listinfo/ozsilverlight
RE: Lots of bind/notify classes
Check out Post#: http://www.sharpcrafters.com/postsharp/documentation/getting-started Example: http://ruskin-dantra.blogspot.com/2009/03/inotifypropertychanged-made-easier.html Not sure if this works in Silverlight land though. Steven Nagy Readify | Senior Developer M: +61 404 044 513 | E: steven.n...@readify.netsip:steven.n...@readify.net | B: azure.snagy.namehttp://azure.snagy.name/ From: ozsilverlight-boun...@ozsilverlight.com [mailto:ozsilverlight-boun...@ozsilverlight.com] On Behalf Of Greg Keogh Sent: Friday, 28 May 2010 4:18 PM To: 'ozSilverlight' Subject: Lots of bind/notify classes Look Dave, I can see you're really upset about this. I honestly think you ought to sit down calmly, take a stress pill, and think things over - HAL (2001) I was wondering if anyone has found a nice way of creating/managing lots of classes that are suitable for binding and implement INotifyPropertyChanged. As you know, you have to keep coding properties like this: public string CompanyName { get {return this.companyNameValue;} set { if (value != this.companyNameValue) { this.companyNameValue = value; NotifyPropertyChanged(CompanyName); } } } You can create a simple base class to factor out the event, but not much else, as there is no way I know of to intercept any arbitrary property setter and add custom processing. Is that right?! Coding the above skeleton dozens or hundreds of times gets tedious and I'm hoping there's a better way. I did consider using a T4 generator to spit out the classes, but that's an obtuse way around the problem and will require extra research time (but I see others have done it already). I have dozens of existing classes with dozens of properties and I'd like to use them for binding, but I'd have to expand every property to be like the same above, which would be hell. Greg ___ ozsilverlight mailing list ozsilverlight@ozsilverlight.com http://prdlxvm0001.codify.net/mailman/listinfo/ozsilverlight
Re: Lots of bind/notify classes
I just saw everyone was alredy talking about PostSharp. Sorry I should read the thread before replying. BTW, it doesn't affect Blendability. I can live with what Steven suggested, of having that extra line bit of code for each property, but it gets a bit messy when you have derived properties. On Fri, May 28, 2010 at 5:09 PM, Miguel Madero m...@miguelmadero.com wrote: For the VMs I'm using an AOP (using CastleDynamicProxy for Debug and PostSharp for Release) to automatically do this for me. Jonas bloggedhttp://jonas.follesoe.no/AutomaticINPCUsingDynamicProxyAndNinject.aspxabout this approach. For PostSharp, I don't have a link, but I could send you a code that works for VS08 and SL3. Also in a somewhat related topic you might want to have a look at MicroModels http://www.paulstovell.com/micromodels-introduction. On Fri, May 28, 2010 at 4:18 PM, Greg Keogh g...@mira.net wrote: *Look Dave, I can see you're really upset about this. I honestly think you ought to sit down calmly, take a stress pill, and think things over*– HAL (2001) I was wondering if anyone has found a nice way of creating/managing lots of classes that are suitable for binding and implement INotifyPropertyChanged. As you know, you have to keep coding properties like this: public string CompanyName { get {return this.companyNameValue;} set { if (value != this.companyNameValue) { this.companyNameValue = value; NotifyPropertyChanged(CompanyName); } } } You can create a simple base class to factor out the event, but not much else, as there is no way I know of to intercept any arbitrary property setter and add custom processing. Is that right?! Coding the above skeleton dozens or hundreds of times gets tedious and I’m hoping there’s a better way. I did consider using a T4 generator to spit out the classes, but that’s an obtuse way around the problem and will require extra research time (but I see others have done it already). I have dozens of existing classes with dozens of properties and I’d like to use them for binding, but I’d have to expand every property to be like the same above, which would be hell. Greg ___ ozsilverlight mailing list ozsilverlight@ozsilverlight.com http://prdlxvm0001.codify.net/mailman/listinfo/ozsilverlight -- Miguel A. Madero Reyes www.miguelmadero.com (blog) m...@miguelmadero.com -- Miguel A. Madero Reyes www.miguelmadero.com (blog) m...@miguelmadero.com ___ ozsilverlight mailing list ozsilverlight@ozsilverlight.com http://prdlxvm0001.codify.net/mailman/listinfo/ozsilverlight
RE: Lots of bind/notify classes
Chaps, I have decided that snippets are the quickest way out of this at the moment. It doesn't modularise or reduce the property code, but at least it means I can create them faster. Actually, I forgot how good snippets are. For some reason I neglected them for the last couple of years, now I'm all invigorated about them again and I'm building my own fresh collection. Greg ___ ozsilverlight mailing list ozsilverlight@ozsilverlight.com http://prdlxvm0001.codify.net/mailman/listinfo/ozsilverlight
Re: Lots of bind/notify classes
+1 for live templates. I like that it u can use a convention to name ur fields with the camelcase version of ur prop name. The other thing consider is using an expression for the propertychanged method instead of passing a string. That makes refactoring easier. RaisePropertyChanged(()=LastName); Sent from my iPhone On 28/05/2010, at 6:19 PM, Stephen Price step...@littlevoices.com wrote: +1 Resharper. That's exactly my process for creating those properties. One day I'll actually write a propOp live template to do the rest of it for me. I think that everytime I create a property... On Fri, May 28, 2010 at 2:32 PM, Steven Nagy steven.n...@readify.net wrote: I might add, that even if you don’t want to introduce Post# then the simple base class + Resharper combination is pretty good. For example, your base class has some methods for raising property changed events. Then your ViewModel needs a property for first name. You use the “prop” code snippet, this expands out very quickly to: public string FirstName { get; set; } Then ALT+Enter with Resharper lets you convert to backing field in total 3 keystrokes: private string _firstName; public string FirstName { get { return _firstName; } set { _firstName = value; } } Then a single call to property changed: private string _firstName; public string FirstName { get { return _firstName; } set { _firstName = value; PropertyChanged(FirstName); } } Not so bad, very minimal keystrokes. Steven Nagy Readify | Senior Developer M: +61 404 044 513 | E: steven.n...@readify.net | B: azure.snagy.name From: ozsilverlight-boun...@ozsilverlight.com [mailto:ozsilverlight- boun...@ozsilverlight.com] On Behalf Of Steven Nagy Sent: Friday, 28 May 2010 4:25 PM To: ozSilverlight Subject: RE: Lots of bind/notify classes Check out Post#: http://www.sharpcrafters.com/postsharp/documentation/getting-started Example: http://ruskin-dantra.blogspot.com/2009/03/inotifypropertychanged-made-easier.html Not sure if this works in Silverlight land though. Steven Nagy Readify | Senior Developer M: +61 404 044 513 | E: steven.n...@readify.net | B: azure.snagy.name From: ozsilverlight-boun...@ozsilverlight.com [mailto:ozsilverlight- boun...@ozsilverlight.com] On Behalf Of Greg Keogh Sent: Friday, 28 May 2010 4:18 PM To: 'ozSilverlight' Subject: Lots of bind/notify classes Look Dave, I can see you're really upset about this. I honestly think you ought to sit down calmly, take a stress pill, and think things over – HAL (2001) I was wondering if anyone has found a nice way of creating/managing lots of classes that are suitable for binding and implement INotifyPropertyChanged. As you know, you have to keep coding properties like this: public string CompanyName { get {return this.companyNameValue;} set { if (value != this.companyNameValue) { this.companyNameValue = value; NotifyPropertyChanged(CompanyName); } } } You can create a simple base class to factor out the event, but not much else, as there is no way I know of to intercept any arbitrary property setter and add custom processing. Is that right?! Coding the above skeleton dozens or hundreds of times gets tedious and I’m hoping there’s a better way. I did consider using a T4 generator to spit out the classes, but that’s an obtuse way around the problem an d will require extra research time (but I see others have done it al ready). I have dozens of existing classes with dozens of properties and I’d like to use them for binding, but I’d have to expand every property to be like the same above, which would be hell. Greg ___ ozsilverlight mailing list ozsilverlight@ozsilverlight.com http://prdlxvm0001.codify.net/mailman/listinfo/ozsilverlight ___ ozsilverlight mailing list ozsilverlight@ozsilverlight.com http://prdlxvm0001.codify.net/mailman/listinfo/ozsilverlight ___ ozsilverlight mailing list ozsilverlight@ozsilverlight.com http://prdlxvm0001.codify.net/mailman/listinfo/ozsilverlight