I suggest you ...

INotifyPropertyChanged

Provide a way for INotifyPropertyChanged to be implemented for you automatically on class.

Provide a way for INPC to be done on auto properties (that you mark in some way)....so that you don't have to unroll the auto property into a field, and raise yourself.

2,417 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    jams shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    27 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • Miha Markic commented  ·   ·  Flag as inappropriate

        I'd like to see a more generic solution, like AOP that would let you change sources during compilation and easy implementation of aspects. Fody is great but it is at IL level and requires post processing which makes aspects harder to write and slower build cycles.

      • Anonymous commented  ·   ·  Flag as inappropriate

        Dans les rues de Milan, Contreras patricia vetement fille 12 ans zara canalisées festival de musique cool dans un tee-shirt Calvin Klein, Lévis shorteralls, Et un sac zara jumbo. Ajouter un peu de piquant avec des pompes d'argent et manteau rouge zara un sac rose poignée supérieure. http://www.zara-paris.com/doudoune-zara.html
        Ensuite, ils ont été amenés à la masse par un homme de l'Atlantique de ville zara vetement homme intelligente qui est entré en production de masse et a vendu sa première paire sur la promenade en 1929.

        zara accessoires

      • panew yaren commented  ·   ·  Flag as inappropriate

        It is the motivation behind why such sorts of significant administration fixings would be appropriately there accessible and it has turned out to be one reason individuals have been going by to the city for more than one reason. http://www.jodhpurescorts.org.in/

      • LegacyOfHerot commented  ·   ·  Flag as inappropriate

        @Travis, I agree - I like the Fody.PropertyChange approach- it hands off the grunt work to the IL compiler. Just decorate the class with [ImplementPropertyChanged]

      • Qwertie commented  ·   ·  Flag as inappropriate

        One problem with implementing INPC is deciding when a property has "changed": do you compare the new value to the old value using `==`? `_old.Equals(value)`? `EqualityComparer<T>.Default.Equals`?

        Another third-party solution to this problem is LeMP, which has various features to help you eliminate all kinds of repetitive code, not just INPC. Here's an example for INPC, though:

        http://ecsharp.net/lemp/avoid-tedium-with-LeMP.html#unroll

      • Marta Dabrowska commented  ·   ·  Flag as inappropriate

        Or it could look like:
        public string Property1 { get; notify set; }
        or
        public string Property1 { get; private notify set; }

      • Fredrik Karlsson commented  ·   ·  Flag as inappropriate

        Create a code snippet, they are awesome. There are also tools that helps you. Just add an attribute and it will work.

        Example is "PostSharp Domain Toolkit"

      • Konstantin Isaev commented  ·   ·  Flag as inappropriate

        Syntax can be like so:
        public class A: INotifyPropertyChanged {
        public string Property1 { get; set; notify as "Property1"; }
        public string Property2 { get; set; notify; } //property name picked automatically as "Property2"
        }

      • Martin commented  ·   ·  Flag as inappropriate

        I like the idea of a NotifyPropertyChanged attribute that causes a standard "if (a != b) ..." test to be generated but offers an override that can take an optional IComparer as a parameter for the more complex test and provide custom control over that test (generating "if (comparer.Compare(a, b) != 0) ...".

        The NotifyPropertyChanged attribute would only then be allowed to be specified against automatic properties on a class that implements INotifyPropertyChanged.

      • Ramon de Klein commented  ·   ·  Flag as inappropriate

        Implementing INotifyPropertyChanged properly requires some repeating programming effort for each property. It also used to be error-prone, but this can be resolved in C# 5 using the CallerMemberName attribute. It would be more convenient to use automatic properties with INotifyPropertyChanged support. The 'SupportINotifyPropertyChanged' attribute can be applied to automatic properties and this result in the following code:

        [SupportINotifyPropertyChanged]
        public string Description { get; set; }

        Is compiled to something like this:

        private string __description;
        public Description
        {
        get { return __description; }
        set {
        if (__description == value) return;
        __description = value;
        var propChanged = (INotifyPropertyChanged)this; /* prevents race condition */
        if (propChanged != null)
        propChanged(this, new PropertyChangedEventArgs("Description"));
        }
        }

        A compilation error will be emitted if the class (or one of its parents) doesn't implement the INotifyPropertyChanged interface.

        As an addition the 'SupportINotifyPropertyChanged' attribute could also take an optional Func<T,T,bool> delegate (or use IEqualityComparer<T>) that is used to check if the new value is different for more complex scenarios.

      • Ramon de Klein commented  ·   ·  Flag as inappropriate

        Implementing INotifyPropertyChanged properly requires some repeating programming effort for each property. It also used to be error-prone, but this can be resolved in C# 5 using the CallerMemberName attribute. It would be more convenient to use automatic properties with INotifyPropertyChanged support. The 'SupportINotifyPropertyChanged' attribute can be applied to automatic properties and this result in the following code:

        [SupportINotifyPropertyChanged]
        public string Description { get; set; }

        Is compiled to something like this:

        private string __description;
        public Description
        {
        get { return __description; }
        set {
        if (__description == value) return;
        __description = value;
        var propChanged = (INotifyPropertyChanged)this; /* prevents race condition */
        if (propChanged != null)
        propChanged(this, new PropertyChangedEventArgs("Description"));
        }
        }

        A compilation error will be emitted if the class (or one of its parents) doesn't implement the INotifyPropertyChanged interface.

        As an addition the 'SupportINotifyPropertyChanged' attribute could also take an optional Func<T,T,bool> delegate (or use IEqualityComparer<T>) that is used to check if the new value is different for more complex scenarios.

      • Brett commented  ·   ·  Flag as inappropriate

        This is improved in VS11 net4.5 to use the method name optionally as [CallerMemberName] string PropertyName where the callername is subsitituted if no explicit name is supplied

      • Miha Markic commented  ·   ·  Flag as inappropriate

        Agree with Schuster-Rainer - AOP is the way to go. Roslyn might have this feature albeit I doubt it (due to the political decisions). As for now, there are AOP 3rd parties ranging from free ones (as RIchard pointed out) to much more powerful (not free, but well worthi it) PostSharp.
        The bottom line is that if MS is to add this feature it will be a part of Roslyn. And yes, I am totally in favor of such a feature.

      • apr commented  ·   ·  Flag as inappropriate

        This idea won't work for a winform/wpf(?) application, when the property is changed in a non-ui thread.

      ← Previous 1

      Feedback and Knowledge Base