Bug Report T461806
Visible to All Users

Code Templates - The "p" template does not trigger the "PropertyChanged" event handler under certain conditions

created 8 years ago

Hi

Let me preface this by saying that I'm in the process of teaching myself C# so my perceived error in CodeRush may well be an error in my own implementation of C# itself.  That being said;

Simple WPF Project  (I would normally use DevExpresses own implementation of MVVM but as I said I'm teaching myself C# and I know this sort of thing used to work in CodeRush Clasic using VB.

I have a simple BindableBase class that provides the base INotifyPropertyChanged implementation:

C#
using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; namespace Vtl_TrackerConfigurationManager.ViewModels { class BindableBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } }

I then create a new class and inherit from BindableBase.  Within that I Type ps Iinvoking the string property template.  What I end up with is the following, but I see no implementation of Property changed as I would have expected.  Is this a CodeRush for Roslyn issue or simply a mess up on my part (presumably in BindableBase)?

C#
using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Vtl_TrackerConfigurationManager.ViewModels { class VtlBaseViewModel : BindableBase { string propertyName; public string PropertyName { get { return propertyName; } set { propertyName = value; } } } }

Dom

Comments (2)

    Just to add to this.  Lest my original implementation of The BindableBase class was incorrect I decided to replace that with the classic tried and tested Josh Smith implementation of a base class implementing INotifyPropertyChanged.  This I know (admittedly using a vb variant) used to have CodeRush property  templates expanding to implement this.

    My guess therefore is that there is some sort of regression bug and CR templates no longer do this as they did.  As I said earlier most times I would actually use your MVVM framework so this would be largely academic, but just at the moment it would be rather useful to have it working.

    Dom

    DevExpress Support Team 8 years ago

      Hi Dom,

      Thank you for the provided code snippets. They helped me reproduce the issue and understand its cause. I have noticed that the "ps" template expands as expected in the context of "VtBaseViewModel" if the "OnPropertyChanged" method has the following implementation:

      C#
      protected void OnPropertyChanged(string name) { var handler = PropertyChanged; if(handler != null) handler(this, new PropertyChangedEventArgs(name)); }

      I guess that the issue is associated with the presence of the following conditional access operation in your code:

      C#
      PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

      It seems that the context of the "ps" template can't be satisfied because of this, so it can't support INotifyPropertyChanged in your case. We will fix this issue as soon as possible.

      Answers approved by DevExpress Support

      created 8 years ago

      We have fixed the issue described in this ticket and will include the fix in our next maintenance update. To apply this solution before the official update, request a hotfix by clicking the corresponding link for product versions you require.

      Note: Hotfixes may be unavailable for beta versions and updates that are about to be released.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.