0
|
1 using System;
|
|
2 using BLToolkit.Common;
|
|
3 using BLToolkit.TypeBuilder.Builders;
|
|
4
|
|
5 namespace BLToolkit.TypeBuilder
|
|
6 {
|
|
7 /// <summary>
|
|
8 /// This attribute allows to control generation of PropertyChanged notification at class level
|
|
9 /// </summary>
|
|
10 [AttributeUsage(AttributeTargets.Interface | AttributeTargets.Class)]
|
|
11 public sealed class PropertyChangedAttribute : AbstractTypeBuilderAttribute
|
|
12 {
|
|
13 /// <summary>
|
|
14 /// Specifies default generation options should be used for PropertyChanged notification
|
|
15 /// </summary>
|
|
16 public PropertyChangedAttribute()
|
|
17 :this(Common.Configuration.NotifyOnEqualSet)
|
|
18 {
|
|
19 }
|
|
20
|
|
21 /// <summary>
|
|
22 /// This constructor allows control of PropertyChanged code generation
|
|
23 /// </summary>
|
|
24 /// <param name="notifyOnEqualSet">See <see cref="NotifyOnEqualSet"/></param>
|
|
25 public PropertyChangedAttribute(bool notifyOnEqualSet)
|
|
26 :this(notifyOnEqualSet, true)
|
|
27 {
|
|
28 }
|
|
29
|
|
30 /// <summary>
|
|
31 /// This constructor allows control of PropertyChanged code generation
|
|
32 /// </summary>
|
|
33 /// <param name="notifyOnEqualSet">See <see cref="NotifyOnEqualSet"/></param>
|
|
34 /// <param name="useReferenceEquals">See <see cref="UseReferenceEquals"/></param>
|
|
35 public PropertyChangedAttribute(bool notifyOnEqualSet, bool useReferenceEquals)
|
|
36 :this(notifyOnEqualSet, useReferenceEquals, true)
|
|
37 {
|
|
38 }
|
|
39
|
|
40 /// <summary>
|
|
41 /// This constructor allows control of PropertyChanged code generation
|
|
42 /// </summary>
|
|
43 /// <param name="notifyOnEqualSet">See <see cref="NotifyOnEqualSet"/></param>
|
|
44 /// <param name="useReferenceEquals">See <see cref="UseReferenceEquals"/></param>
|
|
45 /// <param name="skipSetterOnNoChange">See <see cref="SkipSetterOnNoChange"/></param>
|
|
46 public PropertyChangedAttribute(bool notifyOnEqualSet, bool useReferenceEquals, bool skipSetterOnNoChange)
|
|
47 {
|
|
48 _notifyOnEqualSet = notifyOnEqualSet;
|
|
49 _useReferenceEquals = useReferenceEquals;
|
|
50 _skipSetterOnNoChange = skipSetterOnNoChange;
|
|
51 }
|
|
52
|
|
53 private bool _notifyOnEqualSet;
|
|
54 /// <summary>
|
|
55 /// Controls whether OnPropertyChanged notifications are sent when current value is same as new one.
|
|
56 ///
|
|
57 /// Default value controlled via <see cref="Configuration.NotifyOnEqualSet"/> and by default is set to false
|
|
58 /// </summary>
|
|
59 public bool NotifyOnEqualSet
|
|
60 {
|
|
61 get { return _notifyOnEqualSet; }
|
|
62 set { _notifyOnEqualSet = value; }
|
|
63 }
|
|
64
|
|
65 private bool _useReferenceEquals;
|
|
66 /// <summary>
|
|
67 /// Specifies if <see cref="Object.ReferenceEquals">Object.ReferenceEquals</see> should be used for equality comparison of current and new value
|
|
68 /// for reference types. If value type implements op_Inequality, UseReferenceEquals is ignored.
|
|
69 /// </summary>
|
|
70 public bool UseReferenceEquals
|
|
71 {
|
|
72 get { return _useReferenceEquals; }
|
|
73 set { _useReferenceEquals = value; }
|
|
74 }
|
|
75
|
|
76 private bool _skipSetterOnNoChange;
|
|
77 /// <summary>
|
|
78 /// Specifies whether call to setter is made when current value is same as new one
|
|
79 /// </summary>
|
|
80 public bool SkipSetterOnNoChange
|
|
81 {
|
|
82 get { return _skipSetterOnNoChange; }
|
|
83 set { _skipSetterOnNoChange = value; }
|
|
84 }
|
|
85
|
|
86 public override IAbstractTypeBuilder TypeBuilder
|
|
87 {
|
|
88 get { return new PropertyChangedBuilder(_notifyOnEqualSet, _useReferenceEquals, _skipSetterOnNoChange); }
|
|
89 }
|
|
90 }
|
|
91 }
|