/
IWidget.cs
211 lines (164 loc) · 4.42 KB
/
IWidget.cs
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
using System;
namespace StructureMap.Testing.Widget
{
public interface IWidget
{
void DoSomething();
}
[Pluggable("Color", "Only for testing")]
public class ColorWidget : IWidget, ICloneable
{
private string _Color;
public ColorWidget(string Color)
{
_Color = Color;
}
public string Color
{
get { return _Color; }
set { _Color = value; }
}
#region IWidget Members
public void DoSomething()
{
// TODO: Add ColorWidget.DoSomething implementation
}
#endregion
public override bool Equals(object obj)
{
if (this == obj) return true;
ColorWidget colorWidget = obj as ColorWidget;
if (colorWidget == null) return false;
return Equals(_Color, colorWidget._Color);
}
public override int GetHashCode()
{
return _Color != null ? _Color.GetHashCode() : 0;
}
public object Clone()
{
return MemberwiseClone();
}
}
[Pluggable("AWidget")]
public class AWidget : IWidget
{
public AWidget()
{
}
public void DoSomething()
{
throw new NotImplementedException();
}
}
public class NotPluggableWidget : IWidget
{
private readonly string _name;
public NotPluggableWidget(string name)
{
_name = name;
}
public string Name
{
get { return _name; }
}
#region IWidget Members
public void DoSomething()
{
// TODO: Add NotPluggableWidget.DoSomething implementation
}
#endregion
}
[Pluggable("Money", "Only for testing")]
public class MoneyWidget : IWidget
{
private double _Amount;
public double Amount
{
get { return _Amount; }
set { _Amount = value; }
}
#region IWidget Members
public void DoSomething()
{
// TODO: Add MoneyWidget.DoSomething implementation
}
#endregion
}
[Pluggable("Configuration", "Only for testing")]
public class ConfigurationWidget : IWidget
{
private string _String;
private string _String2;
private int _Int;
private long _Long;
private byte _Byte;
private double _Double;
private bool _Bool;
public ConfigurationWidget(string String, string String2, int Int, long Long, byte Byte, double Double,
bool Bool)
{
this.String = String;
this.String2 = String2;
this.Int = Int;
this.Long = Long;
this.Byte = Byte;
this.Double = Double;
this.Bool = Bool;
}
public string String
{
get { return _String; }
set { _String = value; }
}
public string String2
{
get { return _String2; }
set { _String2 = value; }
}
public int Int
{
get { return _Int; }
set { _Int = value; }
}
public byte Byte
{
get { return _Byte; }
set { _Byte = value; }
}
public long Long
{
get { return _Long; }
set { _Long = value; }
}
public double Double
{
get { return _Double; }
set { _Double = value; }
}
public bool Bool
{
get { return _Bool; }
set { _Bool = value; }
}
[ValidationMethod]
public void Validate()
{
// Throw an exception if Long = 5
if (Long == 5)
{
throw new ApplicationException("Long should not equal 5");
}
}
[ValidationMethod]
public void Validate2()
{
}
#region IWidget Members
public void DoSomething()
{
// TODO: Add ConfigurationTarget.DoSomething implementation
}
#endregion
}
}