1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Text ;
4+
5+ namespace Clojure . Tests . Support
6+ {
7+ public class AlmostEverything
8+ {
9+ // Testing property/field/0-arity-method
10+ public string InstanceField = "InstanceField" ;
11+ public static string StaticField = "StaticField" ;
12+ public string InstanceProperty { get ; set ; } = "InstanceProperty" ;
13+ public static string StaticProperty { get ; set ; } = "StaticProperturn" ;
14+ public string InstanceMethod0 ( ) => "InstanceMethod0" ;
15+ public static string StaticMethod0 ( ) => "StaticMethod0" ;
16+
17+ // for testing reflection on zero-arity member access
18+ // field/property/0-arity-method
19+ // Other classes provide other definitions
20+
21+ // here we have a field
22+ public string ZeroMember = "field" ;
23+
24+ // Testing constructors
25+
26+ string _msg ;
27+ object _data ;
28+
29+ public override string ToString ( )
30+ {
31+ return _msg ;
32+ }
33+
34+ public AlmostEverything ( )
35+ {
36+ _msg = "void" ;
37+ _data = null ;
38+ }
39+
40+ public AlmostEverything ( int x )
41+ {
42+ _msg = "int" ;
43+ _data = x ;
44+ }
45+
46+ public AlmostEverything ( string x )
47+ {
48+ _msg = "string" ;
49+ _data = x ;
50+ }
51+
52+ public AlmostEverything ( ref int x )
53+ {
54+ _msg = "ref int" ;
55+ _data = x ;
56+ x += 1 ;
57+ }
58+
59+ // Trying for some ambiguity in calls with ref parameters
60+ public AlmostEverything ( string x , ref int y )
61+ {
62+ _msg = "string+ref int" ;
63+ _data = x ;
64+ y += 20 ;
65+ }
66+
67+ // Trying for some ambiguity in calls with ref parameters
68+ public AlmostEverything ( int x , ref int y )
69+ {
70+ _msg = "int+ref int" ;
71+ _data = x ;
72+ y += 30 ;
73+ }
74+
75+
76+
77+ // Testing overloads
78+ public string Over ( ) => "no-arg" ;
79+ public int Over ( int v ) => v ;
80+ public double Over ( double v ) => v ;
81+ public object Over ( object v ) => v ;
82+ public string Over ( string format , object arg0 ) => String . Format ( format , arg0 ) ;
83+ public string Over ( string format , object arg0 , object arg1 ) => String . Format ( format , arg0 , arg1 ) ;
84+ public string Over ( string format , params object [ ] args ) => String . Format ( format , args ) ;
85+
86+ // Testing ref/out resolving
87+ public int Out ( int x ) { return x + 10 ; }
88+ public int Out ( ref int x ) { x += 1 ; return x + 20 ; }
89+
90+ // Testing non-resolving of simple arg
91+ public int Out2 ( ref int v ) { return v + 1 ; }
92+
93+ // Testing some ambiguity
94+ public string Ambig ( string x , ref int y ) { y += 10 ; return x + y . ToString ( ) ; }
95+ public int Ambig ( int x , ref int y ) { y += 100 ; return x + y ; }
96+
97+
98+ // Testing ambiguity in the ref
99+ public string AmbigRef ( ref int x ) { x += 111 ; return x . ToString ( ) ; }
100+ public string AmbigRef ( ref string x ) { x += "abc" ; return x ; }
101+
102+ public int Params ( string format , params object [ ] args ) => args . Length ;
103+ }
104+
105+ // For testing reflection
106+ public class AlmostEverything2
107+ {
108+ public string Over ( string format , object arg0 ) => String . Format ( format + "!!!" , arg0 ) ;
109+ public string InstanceField => "InstanceField2" ;
110+ public static string StaticField => "StaticField2" ;
111+ public string InstanceProperty { get ; set ; } = "InstanceProperty2" ;
112+ public static string StaticProperty { get ; set ; } = "StaticProperturn2" ;
113+ public string InstanceMethod0 ( ) => "InstanceMethod02" ;
114+ public static string StaticMethod0 ( ) => "StaticMethod02" ;
115+
116+
117+ // for testing reflection on zero-arity member access
118+ // field/property/0-arity-method
119+ // Other classes provide other definitions
120+
121+ // here we have a property
122+ public string ZeroMember { get ; set ; } = "property" ;
123+ }
124+
125+ // For testing reflection
126+ public class AlmostEverything3
127+ {
128+ // for testing reflection on zero-arity member access
129+ // field/property/0-arity-method
130+ // Other classes provide other definitions
131+
132+ // here we have a zero-arity method
133+ public string ZeroMember ( ) => "method" ;
134+ }
135+
136+ // All attempts at resolving members should fail here.
137+ public class AlmostNothing
138+ {
139+ }
140+
141+
142+ // For testing params, with and without ref/out, with and without ambiguity
143+
144+ public class ParamsTest
145+ {
146+ public static int StaticParams ( int x , params object [ ] ys )
147+ {
148+ return x + ys . Length ;
149+ }
150+
151+ public static int StaticParams ( int x , params string [ ] ys )
152+ {
153+ int count = x ;
154+ foreach ( String y in ys )
155+ count += y . Length ;
156+
157+ return count ;
158+ }
159+
160+ public int InstanceParams ( int x , params object [ ] ys )
161+ {
162+ return x + ys . Length ;
163+ }
164+
165+ public int InstanceParams ( int x , params string [ ] ys )
166+ {
167+ int count = x ;
168+ foreach ( String y in ys )
169+ count += y . Length ;
170+
171+ return count ;
172+ }
173+
174+ public static int StaticRefWithParams ( ref int x , params object [ ] ys )
175+ {
176+ x += ys . Length ;
177+ return ys . Length ;
178+ }
179+
180+
181+ }
182+ }
183+
184+
185+ /*
186+ *
187+ *
188+ * using System;
189+ using System.Collections.Generic;
190+ using System.Linq;
191+ using System.Text;
192+
193+ namespace dm.interop
194+ {
195+ #pragma warning disable IDE1006 // Naming Styles
196+ #pragma warning disable CA1822 // Mark members as static
197+ public class C1
198+ {
199+ // Testing property/field/0-arity-method
200+ public int m1 = 11;
201+
202+ // Testing static poperty/field/0-arity-method
203+ static public int m1s = 110;
204+
205+ // Testing overloads
206+ public void m2() { Console.WriteLine("m2()"); }
207+ public void m2(int v) { Console.WriteLine("m2(int) => {0}",v); }
208+ public void m2(double v) { Console.WriteLine("m2(double) => {0}", v); }
209+ public void m2(object v) { Console.WriteLine("m2(object) => {0}", v); }
210+ public void m2(string format, object arg0) { Console.WriteLine(format, arg0); }
211+ public void m2(string format, object arg0, object arg1) { Console.WriteLine(format, arg0, arg1); }
212+ public void m2(string format, params object[] args) { Console.WriteLine(format, args); }
213+
214+ // Testing ref/out resolving
215+ public int m3(int x) { return x+10; }
216+ public int m3(ref int x) { x += 1; return x+20; }
217+
218+
219+ // Testing non-resolving of simple arg
220+ public int m4(ref int v) { return v + 1; }
221+
222+ // Testing some ambiguity
223+ public string m5(string x, ref int y) { y += 10; return x + y.ToString(); }
224+ public int m5(int x, ref int y) { y += 100; return x+y; }
225+
226+ // Testing ambiguity in the ref
227+ public string m6(ref int x) { x += 111; return x.ToString(); }
228+ public string m6(ref string x) { x += "abc"; return x; }
229+
230+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "<Pending>")]
231+ public void m7(string format, params object[] args) { Console.WriteLine("Count is {0}", args.Length); }
232+ }
233+
234+ public class C2
235+ {
236+ public void m2(string format, object arg0) { Console.WriteLine(format + "!!!!!", arg0); }
237+
238+ public int m1 { get { return 21; } }
239+ static public int m1s { get { return 210; } }
240+ }
241+
242+ public class C3
243+ {
244+ public int m1() { return 31; }
245+ static public int m1s() { return 310; }
246+ }
247+
248+ // All attempts at resolving members should fail here.
249+ public class C4
250+ {
251+ }
252+
253+ // For playing with c-tors
254+ public class C5
255+ {
256+ #pragma warning disable IDE0044 // Add readonly modifier
257+ #pragma warning disable IDE0052 // Remove unread private members
258+ string _msg;
259+ object _data;
260+ #pragma warning restore IDE0052 // Remove unread private members
261+ #pragma warning restore IDE0044 // Add readonly modifier
262+
263+ public override string ToString()
264+ {
265+ return String.Format("Constructed with {0}", _msg);
266+ }
267+
268+ public C5()
269+ {
270+ _msg = "Default c-tor";
271+ _data = null;
272+ }
273+
274+ public C5(int x)
275+ {
276+ _msg = "Int32 c-ctor";
277+ _data = x;
278+ }
279+
280+ public C5(string x)
281+ {
282+ _msg = "String c-ctor";
283+ _data = x;
284+ }
285+
286+ public C5(ref int x)
287+ {
288+ _msg = "Int32-by-ref c-ctor";
289+ _data = x;
290+ x += 1;
291+ }
292+
293+ // Trying for some ambiguity in calls with ref parameters
294+ public C5(string x, ref int y)
295+ {
296+ _msg = "String+int-by-ref c-tor";
297+ _data = x;
298+ y += 20;
299+ }
300+
301+ // Trying for some ambiguity in calls with ref parameters
302+ public C5(int x, ref int y)
303+ {
304+ _msg = "int+int-by-ref c-tor";
305+ _data = x;
306+ y += 30;
307+ }
308+
309+ }
310+
311+ // For testing params, with and without ref/out, with and without ambiguity
312+
313+ public class C6
314+ {
315+ public static int sm1(int x, params object[] ys)
316+ {
317+ return x + ys.Length;
318+ }
319+
320+ public static int sm1(int x, params string[] ys)
321+ {
322+ int count = x;
323+ foreach (String y in ys)
324+ count += y.Length;
325+
326+ return count;
327+ }
328+
329+ public int m1(int x, params object[] ys)
330+ {
331+ return x + ys.Length;
332+ }
333+
334+ public int m1(int x, params string[] ys)
335+ {
336+ int count = x;
337+ foreach (String y in ys)
338+ count += y.Length;
339+
340+ return count;
341+ }
342+
343+ public static int m2(ref int x, params object[] ys)
344+ {
345+ x += ys.Length;
346+ return ys.Length;
347+ }
348+
349+
350+ }
351+
352+ public class ParentClass
353+ {
354+ public static string Create()
355+ {
356+ return "Parent create, no args";
357+ }
358+
359+ public static string Create(string input)
360+ {
361+ return String.Format("Parent create, arg = {0}", input);
362+ }
363+ }
364+
365+ public class DerivedClass : ParentClass
366+ {
367+ public new static string Create()
368+ {
369+ return "Derived create, no args";
370+ }
371+
372+ public new static string Create(string input)
373+ {
374+ return String.Format("Derived create, arg = {0}", input);
375+ }
376+
377+ public static string Create2()
378+ {
379+ return "Derived create2, no args";
380+ }
381+
382+ public static string Create2(string input)
383+ {
384+ return String.Format("Derived create2, arg = {0}", input);
385+ }
386+
387+ }
388+
389+ #pragma warning restore IDE1006 // Naming Styles
390+ #pragma warning restore CA1822 // Mark members as static
391+ }
392+
393+ *
394+ */
0 commit comments