-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathExactCallable.cs
More file actions
194 lines (143 loc) · 5.51 KB
/
ExactCallable.cs
File metadata and controls
194 lines (143 loc) · 5.51 KB
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
using System;
namespace Test
{
public class MainClass
{
public static void Main(string[] args)
{
var test = new Tests<ImplBeta>();
test.Run<Tests<ImplBeta>, ImplBeta>(null);
}
public class Tests<T1> : ImplAlpha where T1 : ImplBeta, new()
{
public void Run<T2, T3>(T2 arg) where T2 : Tests<T3> where T3 : ImplBeta, new()
{
// Expect call to ImplAlpha.M().
Interface int_alpha = new ImplAlpha();
int_alpha.M();
// Expect call to ImplBeta.M().
Interface int_beta = new ImplBeta();
int_beta.M();
// Expect call to ImplAlpha.M().
ImplAlpha alpha_alpha = new ImplAlpha();
alpha_alpha.M();
// Expect call to ImplBeta.M().
Interface int_both = new ImplAlpha();
int_both = new ImplBeta();
int_both.M();
// Expect call to ImplBeta.M().
Interface int_beta_inheriter = new Inheriter();
int_beta_inheriter.M();
// Expect call to UnqualifiedM().
UnqualifiedM();
// Expect call to SecondLevelImpl.M().
Interface int_secondlevelimpl = new SecondLevelImpl();
int_secondlevelimpl.M();
// Expect call to OnlyStaticClass.M().
OnlyStaticClass.M();
// Expect no detected calls as correct implementation cannot be determined (could be ImplAlpha or SecondLevelImpl).
AlphaFactory().M();
// Expect call to ImplBeta.M().
BetaFactory().M();
// Expect no detected calls as correct implementation cannot be determined.
InterfaceFactory().M();
// Expect call to ImplAlpha.M()
base.M();
// Expect call to Tests.M()
this.M();
// Expect call to Tests.M()
M();
// Expect call to ImplAlpha.M2()
M2();
// Expect call to ImplAlpha.M3()
M3();
// Expect call to ImplAlpha.M().
typeof(ImplAlpha).InvokeMember("M", System.Reflection.BindingFlags.Public, null, alpha_alpha, new object[0]);
var methodInfo = typeof(ImplAlpha).GetMethod("M");
// Expect call to ImplAlpha.M().
var args = new object[] { 42 };
methodInfo.Invoke(alpha_alpha, args);
// Expect call to ImplAlpha.M().
methodInfo.Invoke(alpha_alpha, System.Reflection.BindingFlags.InvokeMethod, null, new object[0], System.Globalization.CultureInfo.CurrentCulture);
// Expect call to UnqualifiedM().
typeof(MainClass).InvokeMember("UnqualifiedM", System.Reflection.BindingFlags.Public, null, null, new object[0]);
// Expect call to UnqualifiedM().
var methodInfo2 = new MainClass().GetType().GetMethod("UnqualifiedM");
// Expect call to UnqualifiedM().
methodInfo2.Invoke(null, new object[0]);
// Expect call to UnqualifiedM.M().
methodInfo2.Invoke(null, System.Reflection.BindingFlags.InvokeMethod, null, new object[0], System.Globalization.CultureInfo.CurrentCulture);
// Expect call to MainClass.MethodWithOut
args = new object[] { 42, null };
typeof(MainClass).InvokeMember("MethodWithOut", System.Reflection.BindingFlags.Public, null, null, args);
// Expect call to MainClass.MethodWithOut2
typeof(MainClass).InvokeMember("MethodWithOut2", System.Reflection.BindingFlags.Public, null, null, args);
// Expect call to Tests.M()
arg.M();
// Expect call to ImplBeta.M()
new T1().M();
}
public override void M() { }
}
public interface Interface
{
void M();
}
public class ImplAlpha : Interface
{
public virtual void M() { }
public void M(int i, int j = 42) { }
public void M(string s) { }
public virtual void M2() { }
public void M3() { }
}
public class ImplBeta : Interface
{
public void M() { }
}
public class Inheriter : ImplBeta
{
}
public class SecondLevelImpl : ImplAlpha
{
public override void M() { }
public override void M2() { }
new public void M3() { }
}
static void UnqualifiedM() { }
static class OnlyStaticClass
{
public static void M() { }
}
static ImplAlpha AlphaFactory()
{
return new ImplAlpha();
}
static ImplBeta BetaFactory()
{
return new ImplBeta();
}
static Interface InterfaceFactory()
{
return new ImplAlpha();
}
static void MethodWithOut(int x, out bool positive)
{
positive = x >= 0;
}
static void MethodWithOut2(int x, out object boxed)
{
boxed = x;
}
public void M1()
{
M2();
}
public void M2()
{
if (true)
return;
M1();
}
}
}