My favorites | Sign in
Project Home Downloads Wiki Issues Source
Repository:
Checkout   Browse   Changes   Clones    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System;
using System.ComponentModel;

namespace SyringeControl.WinForms
{
/// <summary>
/// Interface of property objects notifying about value change.
/// Allows to reduce code doubling when implementing <see cref="INotifyPropertyChanged"/> interface.
/// </summary>
/// <typeparam name="T">type of value stored in property</typeparam>
public interface INotifyingProperty<T>
{
/// <summary>
/// Sets property value.
/// Raises <see cref="INotifyingProperty{T}.Changed"/>.
/// </summary>
/// <param name="value">value to be stored in property</param>
void Set(T value);
/// <summary>
/// Returns current value of property.
/// </summary>
/// <returns>value of property</returns>
T Get();
/// <summary>
/// Is raised when property value is changed.
/// Argument corresponds to property name.
/// </summary>
event Action<string> Changed;
}

/// <summary>
/// Base class for implementing <see cref="INotifyingProperty{T}"/>.
/// </summary>
/// <typeparam name="T">type of value stored in property</typeparam>
public abstract class PropertyBase<T> : INotifyingProperty<T>
{
/// <summary>
/// Name of property.
/// If instance of this class is exposed via getter/setter pair, this name should correspond to owner class property name.
/// </summary>
public string Name { get; private set; }
/// <summary>
/// Is raised when property value is changed.
/// Argument corresponds to property name.
/// </summary>
public event Action<string> Changed;
/// <summary>
/// field storing actual value of property.
/// </summary>
protected T innerValue;

/// <summary>
/// Initializes part of fields of <see cref="PropertyBase{T}"/> class.
/// Derived classes should call this constructor.
/// </summary>
/// <param name="propertyName">name of property that will be passed to <see cref="PropertyBase{T}.Changed"/> handlers.</param>
protected PropertyBase(string propertyName)
{
Name = propertyName;
}
/// <summary>
/// Returns current value of property.
/// </summary>
/// <returns>value of property</returns>
public virtual T Get()
{
return innerValue;
}
/// <summary>
/// Sets property value.
/// Raises <see cref="PropertyBase{T}.Changed"/>.
/// </summary>
/// <param name="value">value to be stored in property</param>
public virtual void Set(T value)
{
innerValue = value;
InvokeChanged();
}
/// <summary>
/// Raises <see cref="PropertyBase{T}.Changed"/> event.
/// </summary>
protected void InvokeChanged()
{
var handler = Changed;
if(handler != null)
handler(Name);
}
}


}

Change log

b4e5f52768aa by Yuri Korchyomkin <yuri.korchyomkin> on Aug 9, 2009   Diff
added to IControlView event notifying
about pressing 'Setup' button
moved some classes to separate files
Go to: 
Project members, sign in to write a code review

Older revisions

b50671f1f1dc by Yuri Korchyomkin <yuri.korchyomkin> on Aug 9, 2009   Diff
added a set of classes simplifying
implementation of
INotfyPropertyChanged interface
converted main logic to using these
classes and fluent binding.
...
All revisions of this file

File info

Size: 3187 bytes, 92 lines
Powered by Google Project Hosting