caricature 0.7.5 → 0.7.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +97 -97
- data/Rakefile +309 -310
- data/caricature.gemspec +123 -110
- data/lib/caricature/bacon/integration.rb +75 -75
- data/lib/caricature/bacon.rb +2 -2
- data/lib/caricature/clr/descriptor.rb +159 -159
- data/lib/caricature/clr/event_verification.rb +56 -56
- data/lib/caricature/clr/expectation.rb +100 -100
- data/lib/caricature/clr/isolation.rb +78 -78
- data/lib/caricature/clr/isolator.rb +252 -252
- data/lib/caricature/clr/messenger.rb +51 -49
- data/lib/caricature/clr/method_call_recorder.rb +96 -96
- data/lib/caricature/expectation.rb +1 -1
- data/lib/caricature/method_call_recorder.rb +3 -3
- data/lib/caricature/rspec/integration.rb +118 -118
- data/lib/caricature/version.rb +5 -5
- data/lib/caricature.rb +25 -25
- data/spec/bacon/integration/callback_spec.rb +156 -156
- data/spec/bacon/integration/clr_to_clr_spec.rb +325 -253
- data/spec/bacon/integration/event_spec.rb +97 -97
- data/spec/bacon/integration/indexer_spec.rb +27 -27
- data/spec/bacon/spec_helper.rb +4 -4
- data/spec/bacon/unit/descriptor_spec.rb +212 -212
- data/spec/bacon/unit/sword_spec.rb +39 -39
- data/spec/bacon/unit/verification_spec.rb +103 -103
- data/spec/bin/ClrModels.dll +0 -0
- data/spec/bin/ClrModels.dll.mdb +0 -0
- data/spec/fixtures/ExplodingCar.cs +56 -0
- data/spec/fixtures/ExposedChangedSubscriber.cs +26 -0
- data/spec/fixtures/ExposingWarrior.cs +58 -0
- data/spec/fixtures/IExplodingWarrior.cs +10 -0
- data/spec/fixtures/IExposing.cs +9 -0
- data/spec/fixtures/IExposingBridge.cs +9 -0
- data/spec/fixtures/IExposingWarrior.cs +8 -0
- data/spec/fixtures/IHaveAnIndexer.cs +8 -0
- data/spec/fixtures/IWarrior.cs +13 -0
- data/spec/fixtures/IWeapon.cs +9 -0
- data/spec/fixtures/IndexerCaller.cs +17 -0
- data/spec/fixtures/IndexerContained.cs +20 -0
- data/spec/fixtures/MyClassWithAStatic.cs +16 -0
- data/spec/fixtures/Ninja.cs +34 -0
- data/spec/fixtures/Samurai.cs +29 -0
- data/spec/fixtures/StaticCaller.cs +12 -0
- data/spec/fixtures/Sword.cs +16 -0
- data/spec/fixtures/SwordWithStatics.cs +19 -0
- data/spec/fixtures/clr_interaction.rb +61 -0
- data/spec/fixtures/dagger.rb +11 -0
- data/spec/fixtures/dagger_with_class_members.rb +11 -0
- data/spec/fixtures/sheath.rb +19 -0
- data/spec/fixtures/soldier.rb +29 -0
- data/spec/fixtures/soldier_with_class_members.rb +7 -0
- data/spec/fixtures/swift_cleanup_crew.rb +21 -0
- data/spec/fixtures/with_class_methods.rb +11 -0
- data/spec/{models → models.notused}/ClrModels.cs +241 -241
- data/spec/{models → models.notused}/ruby_models.rb +150 -150
- data/spec/rspec/integration/callback_spec.rb +156 -156
- data/spec/rspec/integration/clr_to_clr_spec.rb +254 -254
- data/spec/rspec/integration/clr_to_ruby_spec.rb +227 -227
- data/spec/rspec/integration/indexer_spec.rb +27 -27
- data/spec/rspec/integration/ruby_to_ruby_spec.rb +271 -271
- data/spec/rspec/spec_helper.rb +12 -12
- data/spec/rspec/unit/core_ext_spec.rb +87 -87
- data/spec/rspec/unit/descriptor_spec.rb +210 -210
- data/spec/rspec/unit/event_spec.rb +16 -16
- data/spec/rspec/unit/expectation_spec.rb +300 -300
- data/spec/rspec/unit/interop_spec.rb +29 -29
- data/spec/rspec/unit/isolation_spec.rb +86 -86
- data/spec/rspec/unit/isolator_spec.rb +219 -219
- data/spec/rspec/unit/messaging_spec.rb +310 -310
- data/spec/rspec/unit/method_call_spec.rb +342 -342
- data/spec/rspec/unit/sword_spec.rb +39 -39
- data/spec/rspec/unit/verification_spec.rb +103 -103
- data/spec/spec_helper.rb +16 -15
- metadata +42 -11
@@ -0,0 +1,19 @@
|
|
1
|
+
class Sheath
|
2
|
+
attr_reader :dagger
|
3
|
+
|
4
|
+
def initialize(dagger)
|
5
|
+
@dagger = dagger
|
6
|
+
end
|
7
|
+
|
8
|
+
def insert(dagger)
|
9
|
+
raise "There is already a dagger in here" if @dagger
|
10
|
+
@dagger = dagger
|
11
|
+
end
|
12
|
+
|
13
|
+
def draw
|
14
|
+
raise "Dagger is nowhere to be found" unless @dagger
|
15
|
+
d = @dagger
|
16
|
+
@dagger = nil
|
17
|
+
d
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class Soldier
|
2
|
+
|
3
|
+
def initialize
|
4
|
+
@life = 10
|
5
|
+
end
|
6
|
+
|
7
|
+
def name
|
8
|
+
"Tommy Boy"
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_s
|
12
|
+
"I'm a soldier"
|
13
|
+
end
|
14
|
+
|
15
|
+
def attack(target, weapon)
|
16
|
+
weapon.attack(target)
|
17
|
+
end
|
18
|
+
|
19
|
+
def is_killed_by?(weapon)
|
20
|
+
weapon.damage > 3
|
21
|
+
end
|
22
|
+
|
23
|
+
def survive_attack_with(weapon)
|
24
|
+
@life - weapon.damage
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class SwiftCleanupCrew
|
2
|
+
|
3
|
+
def initialize(car)
|
4
|
+
@car = car
|
5
|
+
@car_exploded_handler = method(:handle_car_on_exploded)
|
6
|
+
@car.on_exploded.add @car_exploded_handler
|
7
|
+
end
|
8
|
+
|
9
|
+
def handle_car_on_exploded(sender, args)
|
10
|
+
# logic here to cleanup the street, repair buildings etc.
|
11
|
+
end
|
12
|
+
|
13
|
+
def dispose
|
14
|
+
unless @disposed
|
15
|
+
@car.on_exploded.remove @car_exploded_handler
|
16
|
+
@disposed = true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
alias :__dispose__ :dispose
|
20
|
+
|
21
|
+
end
|
@@ -1,241 +1,241 @@
|
|
1
|
-
using System;
|
2
|
-
using System.Collections.Generic;
|
3
|
-
|
4
|
-
namespace ClrModels{
|
5
|
-
public interface IWeapon{
|
6
|
-
int Attack(IWarrior warrior);
|
7
|
-
int Damage();
|
8
|
-
}
|
9
|
-
|
10
|
-
public interface IWarrior
|
11
|
-
{
|
12
|
-
|
13
|
-
int Id { get; }
|
14
|
-
string Name { get; set; }
|
15
|
-
bool IsKilledBy(IWeapon weapon);
|
16
|
-
int Attack(IWarrior target, IWeapon weapon);
|
17
|
-
int SurviveAttackWith(IWeapon weapon);
|
18
|
-
}
|
19
|
-
|
20
|
-
public interface IExposing {
|
21
|
-
event EventHandler<EventArgs> OnIsExposedChanged;
|
22
|
-
bool IsExposed {get; set; }
|
23
|
-
}
|
24
|
-
|
25
|
-
public interface IExposingBridge : IWarrior, IExposing {
|
26
|
-
void SomeMethod();
|
27
|
-
}
|
28
|
-
|
29
|
-
public interface IExposingWarrior : IExposingBridge {
|
30
|
-
void OwnMethod();
|
31
|
-
}
|
32
|
-
|
33
|
-
public interface IExplodingWarrior : IExposingBridge{
|
34
|
-
event EventHandler<EventArgs> OnExploding;
|
35
|
-
void Explode();
|
36
|
-
|
37
|
-
}
|
38
|
-
|
39
|
-
public class ExposingWarrior : IExposingWarrior{
|
40
|
-
private readonly int _id;
|
41
|
-
|
42
|
-
public string Name { get; set; }
|
43
|
-
public int Id { get { return _id; } }
|
44
|
-
|
45
|
-
public int Attack(IWarrior target, IWeapon weapon){
|
46
|
-
return weapon.Attack(target);
|
47
|
-
}
|
48
|
-
|
49
|
-
public bool IsKilledBy(IWeapon weapon)
|
50
|
-
{
|
51
|
-
return weapon.Damage() > 3;
|
52
|
-
}
|
53
|
-
|
54
|
-
public virtual event EventHandler<EventArgs> OnIsExposedChanged;
|
55
|
-
public bool IsExposed {get; set; }
|
56
|
-
|
57
|
-
|
58
|
-
public event EventHandler<EventArgs> OnIsAliveChanged;
|
59
|
-
|
60
|
-
public void Die(){
|
61
|
-
OnIsAliveChanged(this, EventArgs.Empty);
|
62
|
-
}
|
63
|
-
|
64
|
-
public static event EventHandler<EventArgs> OnCountChanged;
|
65
|
-
|
66
|
-
public static void ChangeCount(){
|
67
|
-
OnCountChanged(null, EventArgs.Empty);
|
68
|
-
}
|
69
|
-
|
70
|
-
|
71
|
-
public void SomeMethod(){}
|
72
|
-
public void OwnMethod(){
|
73
|
-
|
74
|
-
}
|
75
|
-
|
76
|
-
private int _life = 10;
|
77
|
-
public int SurviveAttackWith(IWeapon weapon){
|
78
|
-
return _life - weapon.Damage();
|
79
|
-
}
|
80
|
-
|
81
|
-
public void Explode(){
|
82
|
-
IsExposed = !IsExposed;
|
83
|
-
var handler = OnIsExposedChanged;
|
84
|
-
if(handler != null){
|
85
|
-
handler(this, EventArgs.Empty);
|
86
|
-
}
|
87
|
-
}
|
88
|
-
|
89
|
-
public bool HasEventSubscriptions{ get { return OnIsExposedChanged != null; } }
|
90
|
-
}
|
91
|
-
|
92
|
-
public class ExposedChangedSubscriber{
|
93
|
-
|
94
|
-
private readonly IExposingBridge _warrior;
|
95
|
-
|
96
|
-
public ExposedChangedSubscriber(IExposingBridge warrior){
|
97
|
-
_warrior = warrior;
|
98
|
-
_warrior.OnIsExposedChanged += OnExposedChanged;
|
99
|
-
}
|
100
|
-
|
101
|
-
public int Counter { get; set; }
|
102
|
-
public object Sender {get; set; }
|
103
|
-
public EventArgs Args { get; set; }
|
104
|
-
|
105
|
-
private void OnExposedChanged(object sender, EventArgs args){
|
106
|
-
Counter++;
|
107
|
-
Sender = sender;
|
108
|
-
Args = args;
|
109
|
-
}
|
110
|
-
|
111
|
-
}
|
112
|
-
|
113
|
-
public class Sword : IWeapon {
|
114
|
-
|
115
|
-
public virtual int Attack(IWarrior warrior){
|
116
|
-
return warrior.SurviveAttackWith(this);
|
117
|
-
}
|
118
|
-
|
119
|
-
public int Damage(){
|
120
|
-
return 4;
|
121
|
-
}
|
122
|
-
}
|
123
|
-
|
124
|
-
public class SwordWithStatics : Sword{
|
125
|
-
|
126
|
-
static SwordWithStatics(){
|
127
|
-
ClassNaming = "Sword with statics";
|
128
|
-
}
|
129
|
-
|
130
|
-
public SwordWithStatics(){ SwordName = "Sword name for statics"; }
|
131
|
-
|
132
|
-
public void AnotherMethod(){}
|
133
|
-
public static void AStaticMethod(){}
|
134
|
-
public static string ClassNaming { get; set; }
|
135
|
-
public string SwordName{get; set;}
|
136
|
-
}
|
137
|
-
|
138
|
-
public class Ninja : IWarrior{
|
139
|
-
|
140
|
-
public Ninja(){
|
141
|
-
Name = "Tony the Ninja";
|
142
|
-
_id = 1;
|
143
|
-
}
|
144
|
-
|
145
|
-
private readonly int _id;
|
146
|
-
|
147
|
-
public string Name { get; set; }
|
148
|
-
public int Id { get { return _id; } }
|
149
|
-
|
150
|
-
public int Attack(IWarrior target, IWeapon weapon){
|
151
|
-
return weapon.Attack(target);
|
152
|
-
}
|
153
|
-
|
154
|
-
public bool IsKilledBy(IWeapon weapon)
|
155
|
-
{
|
156
|
-
return weapon.Damage() > 3;
|
157
|
-
}
|
158
|
-
|
159
|
-
private int _life = 10;
|
160
|
-
public virtual int SurviveAttackWith(IWeapon weapon){
|
161
|
-
return _life - weapon.Damage();
|
162
|
-
}
|
163
|
-
|
164
|
-
|
165
|
-
}
|
166
|
-
|
167
|
-
public sealed class Samurai : IWarrior{
|
168
|
-
|
169
|
-
private readonly int _id;
|
170
|
-
|
171
|
-
public string Name { get; set; }
|
172
|
-
public int Id { get { return _id; } }
|
173
|
-
|
174
|
-
public int Attack(IWarrior target, IWeapon weapon){
|
175
|
-
return weapon.Attack(target);
|
176
|
-
}
|
177
|
-
|
178
|
-
public bool IsKilledBy(IWeapon weapon)
|
179
|
-
{
|
180
|
-
return weapon.Damage() > 5;
|
181
|
-
}
|
182
|
-
|
183
|
-
private int _life = 10;
|
184
|
-
public int SurviveAttackWith(IWeapon weapon){
|
185
|
-
return _life - weapon.Damage();
|
186
|
-
}
|
187
|
-
|
188
|
-
|
189
|
-
}
|
190
|
-
|
191
|
-
public class MyClassWithAStatic{
|
192
|
-
|
193
|
-
public string HelloWorld(){
|
194
|
-
return "Hello World!";
|
195
|
-
}
|
196
|
-
|
197
|
-
public static string GoodByeWorld(){
|
198
|
-
return "Goodbye world!";
|
199
|
-
}
|
200
|
-
}
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
public class StaticCaller{
|
205
|
-
|
206
|
-
public string CallsStatic(){
|
207
|
-
return MyClassWithAStatic.GoodByeWorld();
|
208
|
-
}
|
209
|
-
}
|
210
|
-
|
211
|
-
public class IndexerContained{
|
212
|
-
|
213
|
-
private Dictionary<string, string> _inner = new Dictionary<string, string>{
|
214
|
-
{ "key1", "value1" },
|
215
|
-
{ "key2", "value2" },
|
216
|
-
{ "key3", "value3" },
|
217
|
-
{ "key4", "value4" }
|
218
|
-
};
|
219
|
-
|
220
|
-
public virtual string this[string name]{
|
221
|
-
get { return _inner[name]; }
|
222
|
-
set { _inner[name] = value; }
|
223
|
-
}
|
224
|
-
}
|
225
|
-
|
226
|
-
public class IndexerCaller{
|
227
|
-
|
228
|
-
public string CallIndexOnClass(IndexerContained klass, string name){
|
229
|
-
return klass[name];
|
230
|
-
}
|
231
|
-
|
232
|
-
public string CallIndexOnInterface(IHaveAnIndexer klass, string name){
|
233
|
-
return klass[name];
|
234
|
-
}
|
235
|
-
|
236
|
-
}
|
237
|
-
|
238
|
-
public interface IHaveAnIndexer{
|
239
|
-
string this[string name]{ get; set; }
|
240
|
-
}
|
241
|
-
}
|
1
|
+
using System;
|
2
|
+
using System.Collections.Generic;
|
3
|
+
|
4
|
+
namespace ClrModels{
|
5
|
+
public interface IWeapon{
|
6
|
+
int Attack(IWarrior warrior);
|
7
|
+
int Damage();
|
8
|
+
}
|
9
|
+
|
10
|
+
public interface IWarrior
|
11
|
+
{
|
12
|
+
|
13
|
+
int Id { get; }
|
14
|
+
string Name { get; set; }
|
15
|
+
bool IsKilledBy(IWeapon weapon);
|
16
|
+
int Attack(IWarrior target, IWeapon weapon);
|
17
|
+
int SurviveAttackWith(IWeapon weapon);
|
18
|
+
}
|
19
|
+
|
20
|
+
public interface IExposing {
|
21
|
+
event EventHandler<EventArgs> OnIsExposedChanged;
|
22
|
+
bool IsExposed {get; set; }
|
23
|
+
}
|
24
|
+
|
25
|
+
public interface IExposingBridge : IWarrior, IExposing {
|
26
|
+
void SomeMethod();
|
27
|
+
}
|
28
|
+
|
29
|
+
public interface IExposingWarrior : IExposingBridge {
|
30
|
+
void OwnMethod();
|
31
|
+
}
|
32
|
+
|
33
|
+
public interface IExplodingWarrior : IExposingBridge{
|
34
|
+
event EventHandler<EventArgs> OnExploding;
|
35
|
+
void Explode();
|
36
|
+
|
37
|
+
}
|
38
|
+
|
39
|
+
public class ExposingWarrior : IExposingWarrior{
|
40
|
+
private readonly int _id;
|
41
|
+
|
42
|
+
public string Name { get; set; }
|
43
|
+
public int Id { get { return _id; } }
|
44
|
+
|
45
|
+
public int Attack(IWarrior target, IWeapon weapon){
|
46
|
+
return weapon.Attack(target);
|
47
|
+
}
|
48
|
+
|
49
|
+
public bool IsKilledBy(IWeapon weapon)
|
50
|
+
{
|
51
|
+
return weapon.Damage() > 3;
|
52
|
+
}
|
53
|
+
|
54
|
+
public virtual event EventHandler<EventArgs> OnIsExposedChanged;
|
55
|
+
public bool IsExposed {get; set; }
|
56
|
+
|
57
|
+
|
58
|
+
public event EventHandler<EventArgs> OnIsAliveChanged;
|
59
|
+
|
60
|
+
public void Die(){
|
61
|
+
OnIsAliveChanged(this, EventArgs.Empty);
|
62
|
+
}
|
63
|
+
|
64
|
+
public static event EventHandler<EventArgs> OnCountChanged;
|
65
|
+
|
66
|
+
public static void ChangeCount(){
|
67
|
+
OnCountChanged(null, EventArgs.Empty);
|
68
|
+
}
|
69
|
+
|
70
|
+
|
71
|
+
public void SomeMethod(){}
|
72
|
+
public void OwnMethod(){
|
73
|
+
|
74
|
+
}
|
75
|
+
|
76
|
+
private int _life = 10;
|
77
|
+
public int SurviveAttackWith(IWeapon weapon){
|
78
|
+
return _life - weapon.Damage();
|
79
|
+
}
|
80
|
+
|
81
|
+
public void Explode(){
|
82
|
+
IsExposed = !IsExposed;
|
83
|
+
var handler = OnIsExposedChanged;
|
84
|
+
if(handler != null){
|
85
|
+
handler(this, EventArgs.Empty);
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
public bool HasEventSubscriptions{ get { return OnIsExposedChanged != null; } }
|
90
|
+
}
|
91
|
+
|
92
|
+
public class ExposedChangedSubscriber{
|
93
|
+
|
94
|
+
private readonly IExposingBridge _warrior;
|
95
|
+
|
96
|
+
public ExposedChangedSubscriber(IExposingBridge warrior){
|
97
|
+
_warrior = warrior;
|
98
|
+
_warrior.OnIsExposedChanged += OnExposedChanged;
|
99
|
+
}
|
100
|
+
|
101
|
+
public int Counter { get; set; }
|
102
|
+
public object Sender {get; set; }
|
103
|
+
public EventArgs Args { get; set; }
|
104
|
+
|
105
|
+
private void OnExposedChanged(object sender, EventArgs args){
|
106
|
+
Counter++;
|
107
|
+
Sender = sender;
|
108
|
+
Args = args;
|
109
|
+
}
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
public class Sword : IWeapon {
|
114
|
+
|
115
|
+
public virtual int Attack(IWarrior warrior){
|
116
|
+
return warrior.SurviveAttackWith(this);
|
117
|
+
}
|
118
|
+
|
119
|
+
public int Damage(){
|
120
|
+
return 4;
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
124
|
+
public class SwordWithStatics : Sword{
|
125
|
+
|
126
|
+
static SwordWithStatics(){
|
127
|
+
ClassNaming = "Sword with statics";
|
128
|
+
}
|
129
|
+
|
130
|
+
public SwordWithStatics(){ SwordName = "Sword name for statics"; }
|
131
|
+
|
132
|
+
public void AnotherMethod(){}
|
133
|
+
public static void AStaticMethod(){}
|
134
|
+
public static string ClassNaming { get; set; }
|
135
|
+
public string SwordName{get; set;}
|
136
|
+
}
|
137
|
+
|
138
|
+
public class Ninja : IWarrior{
|
139
|
+
|
140
|
+
public Ninja(){
|
141
|
+
Name = "Tony the Ninja";
|
142
|
+
_id = 1;
|
143
|
+
}
|
144
|
+
|
145
|
+
private readonly int _id;
|
146
|
+
|
147
|
+
public string Name { get; set; }
|
148
|
+
public int Id { get { return _id; } }
|
149
|
+
|
150
|
+
public int Attack(IWarrior target, IWeapon weapon){
|
151
|
+
return weapon.Attack(target);
|
152
|
+
}
|
153
|
+
|
154
|
+
public bool IsKilledBy(IWeapon weapon)
|
155
|
+
{
|
156
|
+
return weapon.Damage() > 3;
|
157
|
+
}
|
158
|
+
|
159
|
+
private int _life = 10;
|
160
|
+
public virtual int SurviveAttackWith(IWeapon weapon){
|
161
|
+
return _life - weapon.Damage();
|
162
|
+
}
|
163
|
+
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
public sealed class Samurai : IWarrior{
|
168
|
+
|
169
|
+
private readonly int _id;
|
170
|
+
|
171
|
+
public string Name { get; set; }
|
172
|
+
public int Id { get { return _id; } }
|
173
|
+
|
174
|
+
public int Attack(IWarrior target, IWeapon weapon){
|
175
|
+
return weapon.Attack(target);
|
176
|
+
}
|
177
|
+
|
178
|
+
public bool IsKilledBy(IWeapon weapon)
|
179
|
+
{
|
180
|
+
return weapon.Damage() > 5;
|
181
|
+
}
|
182
|
+
|
183
|
+
private int _life = 10;
|
184
|
+
public int SurviveAttackWith(IWeapon weapon){
|
185
|
+
return _life - weapon.Damage();
|
186
|
+
}
|
187
|
+
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
public class MyClassWithAStatic{
|
192
|
+
|
193
|
+
public string HelloWorld(){
|
194
|
+
return "Hello World!";
|
195
|
+
}
|
196
|
+
|
197
|
+
public static string GoodByeWorld(){
|
198
|
+
return "Goodbye world!";
|
199
|
+
}
|
200
|
+
}
|
201
|
+
|
202
|
+
|
203
|
+
|
204
|
+
public class StaticCaller{
|
205
|
+
|
206
|
+
public string CallsStatic(){
|
207
|
+
return MyClassWithAStatic.GoodByeWorld();
|
208
|
+
}
|
209
|
+
}
|
210
|
+
|
211
|
+
public class IndexerContained{
|
212
|
+
|
213
|
+
private Dictionary<string, string> _inner = new Dictionary<string, string>{
|
214
|
+
{ "key1", "value1" },
|
215
|
+
{ "key2", "value2" },
|
216
|
+
{ "key3", "value3" },
|
217
|
+
{ "key4", "value4" }
|
218
|
+
};
|
219
|
+
|
220
|
+
public virtual string this[string name]{
|
221
|
+
get { return _inner[name]; }
|
222
|
+
set { _inner[name] = value; }
|
223
|
+
}
|
224
|
+
}
|
225
|
+
|
226
|
+
public class IndexerCaller{
|
227
|
+
|
228
|
+
public string CallIndexOnClass(IndexerContained klass, string name){
|
229
|
+
return klass[name];
|
230
|
+
}
|
231
|
+
|
232
|
+
public string CallIndexOnInterface(IHaveAnIndexer klass, string name){
|
233
|
+
return klass[name];
|
234
|
+
}
|
235
|
+
|
236
|
+
}
|
237
|
+
|
238
|
+
public interface IHaveAnIndexer{
|
239
|
+
string this[string name]{ get; set; }
|
240
|
+
}
|
241
|
+
}
|