1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4 
5 using Xunit;
6 
7 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.anonmethod001.anonmethod001
8 {
9     // <Title>Anonymous methods</Title>
10     // <Description>
11     // </Description>
12     // <RelatedBugs></RelatedBugs>
13     //<Expects Status=success></Expects>
14     // <Code>
15 
16     public class Bar
17     {
Foo()18         public int Foo()
19         {
20             return 0;
21         }
22     }
23 
24     public class Test
25     {
Foo()26         public delegate int Foo();
27         [Fact]
DynamicCSharpRunTest()28         public static void DynamicCSharpRunTest()
29         {
30             Assert.Equal(0, MainMethod(null));
31         }
32 
MainMethod(string[] args)33         public static int MainMethod(string[] args)
34         {
35             dynamic d = new Bar();
36             Foo del = delegate ()
37             {
38                 return (int)d.Foo();
39             }
40 
41             ;
42             return del();
43         }
44     }
45     // </Code>
46 }
47 
48 
49 
50 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.anonmethod002.anonmethod002
51 {
52     // <Title>Anonymous methods</Title>
53     // <Description>
54     // </Description>
55     // <RelatedBugs></RelatedBugs>
56     //<Expects Status=success></Expects>
57     // <Code>
58 
59     public class Bar
60     {
Foo(int x)61         public int Foo(int x)
62         {
63             return x;
64         }
65     }
66 
67     public class Test
68     {
Foo(int x)69         public delegate int Foo(int x);
70         [Fact]
DynamicCSharpRunTest()71         public static void DynamicCSharpRunTest()
72         {
73             Assert.Equal(0, MainMethod(null));
74         }
75 
MainMethod(string[] args)76         public static int MainMethod(string[] args)
77         {
78             dynamic d = new Bar();
79             Foo del = delegate (int x)
80             {
81                 return (int)d.Foo(x);
82             }
83 
84             ;
85             return del(0);
86         }
87     }
88     // </Code>
89 }
90 
91 
92 
93 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.anonmethod003.anonmethod003
94 {
95     // <Title>Anonymous methods</Title>
96     // <Description>
97     // </Description>
98     // <RelatedBugs></RelatedBugs>
99     //<Expects Status=success></Expects>
100     // <Code>
101 
102     public class Bar
103     {
Foo(int x)104         public int Foo(int x)
105         {
106             return x;
107         }
108     }
109 
110     public class Test
111     {
Foo(dynamic x)112         public delegate int Foo(dynamic x);
113         [Fact]
DynamicCSharpRunTest()114         public static void DynamicCSharpRunTest()
115         {
116             Assert.Equal(0, MainMethod(null));
117         }
118 
MainMethod(string[] args)119         public static int MainMethod(string[] args)
120         {
121             dynamic d = new Bar();
122             Foo del = delegate (dynamic x)
123             {
124                 return (int)d.Foo(x);
125             }
126 
127             ;
128             return del(0);
129         }
130     }
131     // </Code>
132 }
133 
134 
135 
136 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.anonmethod004.anonmethod004
137 {
138     // <Title>Anonymous methods</Title>
139     // <Description>
140     // </Description>
141     // <RelatedBugs></RelatedBugs>
142     //<Expects Status=success></Expects>
143     // <Code>
144     using Microsoft.CSharp.RuntimeBinder;
145 
146     public class Bar
147     {
Foo(int x)148         public int Foo(int x)
149         {
150             return x;
151         }
152     }
153 
154     public class Test
155     {
Foo(dynamic x)156         public delegate int Foo(dynamic x);
157         [Fact]
DynamicCSharpRunTest()158         public static void DynamicCSharpRunTest()
159         {
160             Assert.Equal(0, MainMethod(null));
161         }
162 
MainMethod(string[] args)163         public static int MainMethod(string[] args)
164         {
165             dynamic d = new Bar();
166             Foo del = delegate (object x)
167             {
168                 return (int)d.Foo(x);
169             }
170 
171             ;
172             int rez;
173             try
174             {
175                 rez = del(0);
176             }
177             catch (RuntimeBinderException)
178             {
179                 return 0;
180             }
181 
182             return 1;
183         }
184     }
185     // </Code>
186 }
187 
188 
189 
190 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.anonmethod004b.anonmethod004b
191 {
192     // <Title>Anonymous methods</Title>
193     // <Description>
194     // </Description>
195     // <RelatedBugs></RelatedBugs>
196     //<Expects Status=success></Expects>
197     // <Code>
198 
199     public class Bar
200     {
Foo(int x)201         public int Foo(int x)
202         {
203             return x;
204         }
205     }
206 
207     public class Test
208     {
Foo(dynamic x)209         public delegate int Foo(dynamic x);
210         [Fact]
DynamicCSharpRunTest()211         public static void DynamicCSharpRunTest()
212         {
213             Assert.Equal(0, MainMethod(null));
214         }
215 
MainMethod(string[] args)216         public static int MainMethod(string[] args)
217         {
218             dynamic d = new Bar();
219             Foo del = delegate (dynamic x)
220             {
221                 return (int)d.Foo(x);
222             }
223 
224             ;
225             return del(0);
226         }
227     }
228     // </Code>
229 }
230 
231 
232 
233 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.anonmethod005.anonmethod005
234 {
235     // <Title>Anonymous methods</Title>
236     // <Description>
237     // </Description>
238     // <RelatedBugs></RelatedBugs>
239     //<Expects Status=success></Expects>
240     // <Code>
241 
242     public class Bar
243     {
244         public int Foo
245         {
246             get
247             {
248                 return 0;
249             }
250         }
251     }
252 
253     public class Test
254     {
Foo()255         public delegate int Foo();
256         [Fact]
DynamicCSharpRunTest()257         public static void DynamicCSharpRunTest()
258         {
259             Assert.Equal(0, MainMethod(null));
260         }
261 
MainMethod(string[] args)262         public static int MainMethod(string[] args)
263         {
264             dynamic d = new Bar();
265             Foo del = delegate ()
266             {
267                 return (int)d.Foo;
268             }
269 
270             ;
271             return del();
272         }
273     }
274     // </Code>
275 }
276 
277 
278 
279 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.anonmethod006.anonmethod006
280 {
281     // <Title>Anonymous methods</Title>
282     // <Description>
283     // </Description>
284     // <RelatedBugs></RelatedBugs>
285     // <Expects Status=success></Expects>
286     // <Code>
287     using Microsoft.CSharp.RuntimeBinder;
288 
289     public class Bar
290     {
Foo(int x)291         public int Foo(int x)
292         {
293             return x;
294         }
295     }
296 
Foo2(object x)297     public delegate int Foo2(object x);
Bar2(dynamic d)298     public delegate int Bar2(dynamic d);
299     public class Test
300     {
Foo(dynamic x)301         public delegate int Foo(dynamic x);
302         [Fact]
DynamicCSharpRunTest()303         public static void DynamicCSharpRunTest()
304         {
305             Assert.Equal(0, MainMethod(null));
306         }
307 
MainMethod(string[] args)308         public static int MainMethod(string[] args)
309         {
310             dynamic d = new Bar();
311             Foo del = delegate (dynamic x)
312             {
313                 return (int)d.Foo(x);
314             }
315 
316             ;
317             int ret = del(0);
318             Foo2 del22 = delegate (dynamic x)
319             {
320                 Bar2 del2 = delegate (object o)
321                 {
322                     return (int)d.Foo(o);
323                 }
324 
325                 ;
326                 return del2(x);
327             }
328 
329             ;
330             try
331             {
332                 ret += del22(0);
333             }
334             catch (RuntimeBinderException)
335             {
336                 return 0;
337             }
338 
339             return 1;
340         }
341     }
342     // </Code>
343 }
344 
345 
346 
347 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.anonmethod006b.anonmethod006b
348 {
349     // <Title>Anonymous methods</Title>
350     // <Description>
351     // </Description>
352     // <RelatedBugs></RelatedBugs>
353     // <Expects Status=success></Expects>
354     // <Code>
355 
356     public class Bar
357     {
Foo(int x)358         public int Foo(int x)
359         {
360             return x;
361         }
362     }
363 
Foo2(object x)364     public delegate int Foo2(object x);
Bar2(dynamic d)365     public delegate int Bar2(dynamic d);
366     public class Test
367     {
Foo(dynamic x)368         public delegate int Foo(dynamic x);
369         [Fact]
DynamicCSharpRunTest()370         public static void DynamicCSharpRunTest()
371         {
372             Assert.Equal(0, MainMethod(null));
373         }
374 
MainMethod(string[] args)375         public static int MainMethod(string[] args)
376         {
377             dynamic d = new Bar();
378             Foo del = delegate (dynamic x)
379             {
380                 return (int)d.Foo(x);
381             }
382 
383             ;
384             int ret = del(0);
385             Foo2 del22 = delegate (dynamic x)
386             {
387                 Bar2 del2 = delegate (dynamic o)
388                 {
389                     return (int)d.Foo(o);
390                 }
391 
392                 ;
393                 return del2(x);
394             }
395 
396             ;
397             ret += del22(0);
398             return 0 == ret ? 0 : 1;
399         }
400     }
401     // </Code>
402 }
403 
404 
405 
406 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.anonmethod008.anonmethod008
407 {
408     // <Title>Anonymous methods</Title>
409     // <Description>
410     // </Description>
411     // <RelatedBugs></RelatedBugs>
412     //<Expects Status=success></Expects>
413     // <Code>
414 
415     public class Bar
416     {
Foo(int x)417         public int Foo(int x)
418         {
419             return x;
420         }
421     }
422 
423     public class Test
424     {
Foo(object x)425         public delegate int Foo(object x);
Bar2(dynamic d)426         public delegate int Bar2(dynamic d);
427         [Fact]
DynamicCSharpRunTest()428         public static void DynamicCSharpRunTest()
429         {
430             Assert.Equal(0, MainMethod(null));
431         }
432 
MainMethod(string[] args)433         public static int MainMethod(string[] args)
434         {
435             dynamic d = new Bar();
436             try
437             {
438                 Foo del = delegate (dynamic x)
439                 {
440                     Bar2 del2 = delegate (object o)
441                     {
442                         return (int)d.Foo();
443                     }
444 
445                     ;
446                     return del2(x);
447                 }
448 
449                 ;
450                 return del(0);
451             }
452             catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
453             {
454                 if (ErrorVerifier.Verify(ErrorMessageId.BadArgCount, e.Message, "Foo", "0"))
455                     return 0;
456             }
457 
458             return 1;
459         }
460     }
461     // </Code>
462 }
463 
464 
465 
466 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.argument001.argument001
467 {
468     // <Title>Argument to method invocation</Title>
469     // <Description>
470     // </Description>
471     // <RelatedBugs></RelatedBugs>
472     //<Expects Status=success></Expects>
473     // <Code>
474     public class MyClass
475     {
Foo(object o)476         public void Foo(object o)
477         {
478             if ((int)o == 3)
479                 Test.Status = 1;
480             else
481                 Test.Status = 2;
482         }
483     }
484 
485     public class Test
486     {
487         public static int Status;
488         [Fact]
DynamicCSharpRunTest()489         public static void DynamicCSharpRunTest()
490         {
491             Assert.Equal(0, MainMethod(null));
492         }
493 
MainMethod(string[] args)494         public static int MainMethod(string[] args)
495         {
496             MyClass mc = new MyClass();
497             dynamic d = 3;
498             mc.Foo(d);
499             if (Test.Status != 1)
500                 return 1;
501             return 0;
502         }
503     }
504     // </Code>
505 }
506 
507 
508 
509 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.argument002.argument002
510 {
511     // <Title>Argument to method invocation</Title>
512     // <Description>
513     // </Description>
514     // <RelatedBugs></RelatedBugs>
515     //<Expects Status=success></Expects>
516     // <Code>
517     public class MyClass
518     {
Foo(dynamic o)519         public void Foo(dynamic o)
520         {
521             if ((int)o == 3)
522                 Test.Status = 1;
523             else
524                 Test.Status = 2;
525         }
526     }
527 
528     public class Test
529     {
530         public static int Status;
531         [Fact]
DynamicCSharpRunTest()532         public static void DynamicCSharpRunTest()
533         {
534             Assert.Equal(0, MainMethod(null));
535         }
536 
MainMethod(string[] args)537         public static int MainMethod(string[] args)
538         {
539             MyClass mc = new MyClass();
540             object d = 3;
541             mc.Foo(d);
542             if (Test.Status != 1)
543                 return 1;
544             return 0;
545         }
546     }
547     // </Code>
548 }
549 
550 
551 
552 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.array001.array001
553 {
554     // <Title>Special Array methods</Title>
555     // <Description>
556     // </Description>
557     // <RelatedBugs></RelatedBugs>
558     // <Expects Status=success></Expects>
559     // <Code>
560 
561     public class Test
562     {
563         [Fact]
DynamicCSharpRunTest()564         public static void DynamicCSharpRunTest()
565         {
566             Assert.Equal(0, MainMethod(null));
567         }
568 
MainMethod(string[] args)569         public static int MainMethod(string[] args)
570         {
571             dynamic d = new[]
572             {
573             1, 2, 3
574             }
575 
576             ;
577             int result = 3;
578             try
579             {
580                 d.Address(1);
581             }
582             catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
583             {
584                 if (ErrorVerifier.Verify(ErrorMessageId.NoSuchMember, e.Message, "System.Array", "Address"))
585                     result--;
586             }
587 
588             try
589             {
590                 d.Get(1);
591             }
592             catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
593             {
594                 if (ErrorVerifier.Verify(ErrorMessageId.NoSuchMember, e.Message, "System.Array", "Get"))
595                     result--;
596             }
597 
598             try
599             {
600                 d.Set(1);
601             }
602             catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
603             {
604                 if (ErrorVerifier.Verify(ErrorMessageId.NoSuchMember, e.Message, "System.Array", "Set"))
605                     result--;
606             }
607 
608             return result;
609         }
610     }
611     // </Code>
612 }
613 
614 
615 
616 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.array002.array002
617 {
618     // <Title>Special Array methods</Title>
619     // <Description>
620     // </Description>
621     // <RelatedBugs></RelatedBugs>
622     // <Expects Status=success></Expects>
623     // <Code>
624     public class Program
625     {
626         [Fact]
DynamicCSharpRunTest()627         public static void DynamicCSharpRunTest()
628         {
629             Assert.Equal(0, MainMethod(null));
630         }
631 
MainMethod(string[] args)632         public static int MainMethod(string[] args)
633         {
634             dynamic d2 = new object();
635             d2 = "adfa";
636             try
637             {
638                 d2[1] = 4;
639             }
640             catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
641             {
642                 if (ErrorVerifier.Verify(ErrorMessageId.AssgReadonlyProp, e.Message, "string.this[int]"))
643                     return 0;
644             }
645 
646             return 1;
647         }
648     }
649     // </Code>
650 }
651 
652 
653 
654 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.array003.array003
655 {
656     // <Title>Indexing in arrays using uints/ulongs</Title>
657     // <Description>
658     // </Description>
659     // <RelatedBugs></RelatedBugs>
660     // <Expects Status=success></Expects>
661     // <Code>
662     public class C
663     {
664         [Fact]
DynamicCSharpRunTest()665         public static void DynamicCSharpRunTest()
666         {
667             Assert.Equal(0, MainMethod());
668         }
669 
MainMethod()670         public static int MainMethod()
671         {
672             int test = 0, success = 0;
673             dynamic idx;
674             var arr = new int[5];
675             test++;
676             idx = (uint)2;
677             arr[idx] = 2;
678             if (arr[idx] == 2)
679                 success++;
680             test++;
681             idx = (long)1;
682             arr[idx] = 3;
683             if (arr[idx] == 3)
684                 success++;
685             test++;
686             idx = (ulong)3;
687             arr[idx] = 4;
688             if (arr[idx] == 4)
689                 success++;
690             return test == success ? 0 : 1;
691         }
692     }
693     // </Code>
694 }
695 
696 
697 
698 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.array004.array004
699 {
700     // <Title>Indexing in arrays using uints/ulongs</Title>
701     // <Description>
702     // </Description>
703     // <RelatedBugs></RelatedBugs>
704     // <Expects Status=success></Expects>
705     // <Code>
706     public class C
707     {
708         [Fact]
DynamicCSharpRunTest()709         public static void DynamicCSharpRunTest()
710         {
711             Assert.Equal(0, MainMethod());
712         }
713 
MainMethod()714         public static int MainMethod()
715         {
716             int test = 0, success = 0;
717             dynamic idx;
718             dynamic rez;
719             test++;
720             idx = (uint)2;
721             rez = new int[idx];
722             if (rez.Length == 2)
723                 success++;
724             test++;
725             idx = (long)1;
726             rez = new string[idx];
727             ;
728             if (rez.Length == 1)
729                 success++;
730             test++;
731             idx = (ulong)3;
732             rez = new decimal[idx];
733             if (rez.Length == 3)
734                 success++;
735             return test == success ? 0 : 1;
736         }
737     }
738     // </Code>
739 }
740 
741 
742 
743 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.array005.array005
744 {
745     // <Title>Array indexers</Title>
746     // <Description>
747     // </Description>
748     // <RelatedBugs></RelatedBugs>
749     // <Expects Status=success></Expects>
750     // <Code>
751 
752     public class Program
753     {
754         [Fact]
DynamicCSharpRunTest()755         public static void DynamicCSharpRunTest()
756         {
757             Assert.Equal(0, MainMethod());
758         }
759 
MainMethod()760         public static int MainMethod()
761         {
762             int rez = 0;
763             dynamic d1;
764             //test long
765             d1 = 0L;
766             rez += Program.Test(d1);
767             //short
768             short? s = 0;
769             d1 = s;
770             rez += Program.Test(d1);
771             //byte
772             byte b = 0;
773             d1 = b;
774             rez += Program.Test(d1);
775             //char
776             char c = (char)0;
777             d1 = c;
778             rez += Program.Test(d1);
779             return rez;
780         }
781 
Test(dynamic d1)782         public static int Test(dynamic d1)
783         {
784             int tests = 0, success = 0;
785             dynamic arr = new int[]
786             {
787             100, 200, 300, 400, 500, 600
788             }
789 
790             ;
791             tests++;
792             if (arr[d1] == 100)
793                 success++;
794             tests++;
795             if (arr[d1 + 4] == 500)
796                 success++;
797             tests++;
798             arr[d1] = 44;
799             if (arr[d1] == 44)
800                 success++;
801             tests++;
802             arr[d1 + 5L] = 55;
803             if (arr[d1 + 5] == 55)
804                 success++;
805             tests++;
806             arr = new int[3][];
807             arr[0] = new int[]
808             {
809             1, 2, 3, 4, 5
810             }
811 
812             ;
813             if (arr[d1][d1 + (short)2] == 3)
814                 success++;
815             tests++;
816             arr = new int[2, 2]
817             {
818             {
819             1, 2
820             }
821 
822             , {
823             3, 4
824             }
825             }
826 
827             ;
828             if (arr[d1 + 0L, d1] == 1)
829                 success++;
830             return tests - success; //should be 0 in case of success
831         }
832     }
833     // </Code>
834 }
835 
836 
837 
838 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.array006.array006
839 {
840     // <Title>Array indexers</Title>
841     // <Description>
842     // </Description>
843     // <RelatedBugs></RelatedBugs>
844     // <Expects Status=success></Expects>
845     // <Code>
846 
847     public class Program
848     {
849         [Fact]
DynamicCSharpRunTest()850         public static void DynamicCSharpRunTest()
851         {
852             Assert.Equal(0, MainMethod());
853         }
854 
MainMethod()855         public static int MainMethod()
856         {
857             //test ulong
858             dynamic d1;
859             int rez = 0;
860             d1 = 0UL;
861             rez += Program.Test(d1);
862             return rez;
863         }
864 
Test(dynamic d1)865         public static int Test(dynamic d1)
866         {
867             int tests = 0, success = 0;
868             dynamic arr = new int[]
869             {
870             100, 200, 300, 400, 500, 600
871             }
872 
873             ;
874             tests++;
875             if (arr[d1] == 100)
876                 success++;
877             tests++;
878             if (arr[d1 + 4] == 500)
879                 success++;
880             tests++;
881             arr[d1] = 44;
882             if (arr[d1] == 44)
883                 success++;
884             tests++;
885             arr[d1 + 5] = 55;
886             if (arr[d1 + 5] == 55)
887                 success++;
888             tests++;
889             arr = new int[3][];
890             arr[0] = new int[]
891             {
892             1, 2, 3, 4, 5
893             }
894 
895             ;
896             if (arr[d1][d1 + (byte)2] == 3)
897                 success++;
898             tests++;
899             arr = new int[2, 2]
900             {
901             {
902             1, 2
903             }
904 
905             , {
906             3, 4
907             }
908             }
909 
910             ;
911             if (arr[d1 + 0, d1] == 1)
912                 success++;
913             return tests - success; //should be 0 in case of success
914         }
915     }
916     // </Code>
917 }
918 
919 
920 
921 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.array007.array007
922 {
923     // <Title>Array indexers</Title>
924     // <Description>
925     // </Description>
926     // <RelatedBugs></RelatedBugs>
927     // <Expects Status=success></Expects>
928     // <Code>
929     using System;
930 
931     public class Program
932     {
933         [Fact]
DynamicCSharpRunTest()934         public static void DynamicCSharpRunTest()
935         {
936             Assert.Equal(0, MainMethod());
937         }
938 
MainMethod()939         public static int MainMethod()
940         {
941             //test long
942             dynamic d1;
943             int rez = 0;
944             d1 = long.MaxValue;
945             dynamic arr = new int[]
946             {
947             100, 200, 300, 400, 500, 600
948             }
949 
950             ;
951             try
952             {
953                 if (arr[d1] == 100)
954                     rez = 1;
955             }
956             catch (System.OverflowException)
957             {
958                 rez = 0;
959             }
960 
961             return rez;
962         }
963     }
964     // </Code>
965 }
966 
967 
968 
969 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.array008.array008
970 {
971     // <Title>Array indexers</Title>
972     // <Description>
973     // </Description>
974     // <RelatedBugs></RelatedBugs>
975     // <Expects Status=success></Expects>
976     // <Code>
977 
978     public class Program
979     {
980         [Fact]
DynamicCSharpRunTest()981         public static void DynamicCSharpRunTest()
982         {
983             Assert.Equal(0, MainMethod());
984         }
985 
MainMethod()986         public static int MainMethod()
987         {
988             int rez = 0;
989             dynamic d = new Test();
990             dynamic idx = 0L;
991             try
992             {
993                 d[idx] = 4;
994                 rez = 1;
995             }
996             catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
997             {
998                 if (ErrorVerifier.Verify(ErrorMessageId.BadArgTypes, e.Message, "Test.this[int]"))
999                     rez = 0;
1000                 else
1001                     rez = 1;
1002             }
1003 
1004             try
1005             {
1006                 var x = d[idx];
1007                 rez = 1;
1008             }
1009             catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
1010             {
1011                 if (ErrorVerifier.Verify(ErrorMessageId.BadArgTypes, e.Message, "Test.this[int]"))
1012                     rez = 0;
1013                 else
1014                     rez = 1;
1015             }
1016 
1017             return rez;
1018         }
1019     }
1020 
1021     public class Test
1022     {
1023         public int this[int x]
1024         {
1025             get
1026             {
1027                 return 1;
1028             }
1029 
1030             set
1031             {
1032             }
1033         }
1034     }
1035     // </Code>
1036 }
1037 
1038 
1039 
1040 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.array010.array010
1041 {
1042     // <Title>Array - dynamic index</Title>
1043     // <Description> LINQ query mixed with dynamic returns incorrect result
1044     //      compiler seems to reuse the for-loop local iterator variable and its value in nest foreach loop if it's dynamic
1045     // </Description>
1046     // <RelatedBugs></RelatedBugs>
1047     // <Expects Status=success></Expects>
1048     // <Code>
1049     using System.Collections;
1050     using System.Collections.Generic;
1051 
1052     public class Test
1053     {
1054         [Fact]
DynamicCSharpRunTest()1055         public static void DynamicCSharpRunTest()
1056         {
1057             Assert.Equal(0, MainMethod());
1058         }
1059 
MainMethod()1060         public static int MainMethod()
1061         {
1062             bool ret = true;
1063             var ary = new[]
1064             {
1065             1, 2, 3
1066             }
1067 
1068             ;
1069             for (int i = 0; i < ary.Length; i++)
1070             {
1071                 ret &= (i == ary[(dynamic)i] - 1);
1072             }
1073 
1074             for (dynamic i = ary[0]; i <= ary.Length; i++)
1075             {
1076                 ret &= (i == ary[i - 1]);
1077             }
1078 
1079             var dx = new Test();
1080             int id = 0;
1081             foreach (dynamic it in Iter())
1082             {
1083                 ret &= (ary[id++] == ary[dx - it]);
1084             }
1085 
1086             var slist = new[]
1087             {
1088             "AAA", "BB", "C"
1089             }
1090 
1091             ;
1092             dynamic idx = -1;
1093             id = 0;
1094             while (++idx < slist.Length)
1095             {
1096                 ret &= slist[id++] == slist[idx];
1097             }
1098 
1099             // works before fix
1100             var vlist = new[]
1101             {
1102             3, 2, 1
1103             }
1104 
1105             ;
1106             var list2 = new Dictionary<int, string>();
1107             list2.Add(2, "AAA");
1108             list2.Add(3, "BB");
1109             list2.Add(1, "C");
1110             id = 3;
1111             for (dynamic a = 3; a > 0; a--)
1112             {
1113                 ret &= list2[a] == list2[id--];
1114             }
1115 
1116             ret &= new Test().Bug816133();
1117             return ret ? 0 : 1;
1118         }
1119 
Iter()1120         private static IEnumerable Iter()
1121         {
1122             yield return byte.MaxValue;
1123             yield return byte.MaxValue - 1;
1124             yield break;
1125         }
1126 
operator ushort(Test t)1127         public static implicit operator ushort (Test t)
1128         {
1129             return byte.MaxValue;
1130         }
1131 
1132         /// <summary>
1133         /// Expected: 1 2 1 2
1134         /// Actual:   2 0 1 2
1135         /// </summary>
Bug816133()1136         private bool Bug816133()
1137         {
1138             bool ret = true;
1139             int[] ary = new int[2];
1140             for (dynamic i = 1; i <= 2; i++)
1141                 ary[i - 1] = i;
1142             int count = 1;
1143             foreach (int i in new Test().Iter512(ary))
1144             {
1145                 ret &= count++ == i;
1146             }
1147 
1148             return ret;
1149         }
1150 
1151         // public method
Iter512(int[] t)1152         public IEnumerable Iter512(int[] t)
1153         {
1154             int index = 0;
1155             yield return t[index++];
1156             yield return t[index++];
1157         }
1158     }
1159 }
1160 
1161 
1162 
1163 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.arrayinit001.arrayinit001
1164 {
1165     public class Test
1166     {
1167         [Fact]
DynamicCSharpRunTest()1168         public static void DynamicCSharpRunTest()
1169         {
1170             Assert.Equal(0, MainMethod(null));
1171         }
1172 
MainMethod(string[] args)1173         public static int MainMethod(string[] args)
1174         {
1175             dynamic[] d = new dynamic[]
1176             {
1177             1, null, "Foo"
1178             }
1179 
1180             ;
1181             if ((int)d[0] != 1)
1182                 return 1;
1183             if (d[1] != null)
1184                 return 1;
1185             if ((string)d[2] != "Foo")
1186                 return 1;
1187             return 0;
1188         }
1189     }
1190     // </Code>
1191 }
1192 
1193 
1194 
1195 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.arrayinit002.arrayinit002
1196 {
1197     public class Test
1198     {
1199         [Fact]
DynamicCSharpRunTest()1200         public static void DynamicCSharpRunTest()
1201         {
1202             Assert.Equal(0, MainMethod(null));
1203         }
1204 
MainMethod(string[] args)1205         public static int MainMethod(string[] args)
1206         {
1207             object[] o = new object[]
1208             {
1209             1, null, "Foo"
1210             }
1211 
1212             ;
1213             dynamic[] d = o;
1214             if ((int)d[0] != 1)
1215                 return 1;
1216             if (d[1] != null)
1217                 return 1;
1218             if ((string)d[2] != "Foo")
1219                 return 1;
1220             return 0;
1221         }
1222     }
1223     // </Code>
1224 }
1225 
1226 
1227 
1228 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.arrayinit003.arrayinit003
1229 {
1230     public class Test
1231     {
1232         [Fact]
DynamicCSharpRunTest()1233         public static void DynamicCSharpRunTest()
1234         {
1235             Assert.Equal(0, MainMethod(null));
1236         }
1237 
MainMethod(string[] args)1238         public static int MainMethod(string[] args)
1239         {
1240             object o = 3;
1241             dynamic[] d = new dynamic[]
1242             {
1243             o
1244             }
1245 
1246             ;
1247             if ((int)d[0] != 3)
1248                 return 1;
1249             return 0;
1250         }
1251     }
1252     // </Code>
1253 }
1254 
1255 
1256 
1257 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.arrayinit004.arrayinit004
1258 {
1259     public class Test
1260     {
1261         [Fact]
DynamicCSharpRunTest()1262         public static void DynamicCSharpRunTest()
1263         {
1264             Assert.Equal(0, MainMethod(null));
1265         }
1266 
MainMethod(string[] args)1267         public static int MainMethod(string[] args)
1268         {
1269             object o = 3;
1270             dynamic[] d = new object[]
1271             {
1272             o
1273             }
1274 
1275             ;
1276             if ((int)d[0] != 3)
1277                 return 1;
1278             return 0;
1279         }
1280     }
1281     // </Code>
1282 }
1283 
1284 
1285 
1286 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.arrayinit005.arrayinit005
1287 {
1288     public class Test
1289     {
1290         [Fact]
DynamicCSharpRunTest()1291         public static void DynamicCSharpRunTest()
1292         {
1293             Assert.Equal(0, MainMethod(null));
1294         }
1295 
MainMethod(string[] args)1296         public static int MainMethod(string[] args)
1297         {
1298             object o = 3;
1299             object[] d = new dynamic[]
1300             {
1301             o
1302             }
1303 
1304             ;
1305             if ((int)d[0] != 3)
1306                 return 1;
1307             return 0;
1308         }
1309     }
1310     // </Code>
1311 }
1312 
1313 
1314 
1315 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.arrayinit006.arrayinit006
1316 {
1317     public class Test
1318     {
1319         [Fact]
DynamicCSharpRunTest()1320         public static void DynamicCSharpRunTest()
1321         {
1322             Assert.Equal(0, MainMethod(null));
1323         }
1324 
MainMethod(string[] args)1325         public static int MainMethod(string[] args)
1326         {
1327             object o = 3;
1328             dynamic d = 4;
1329             object[] od = new dynamic[]
1330             {
1331             o, d
1332             }
1333 
1334             ;
1335             if ((int)od[0] != 3)
1336                 return 1;
1337             if ((int)od[1] != 4)
1338                 return 1;
1339             return 0;
1340         }
1341     }
1342     // </Code>
1343 }
1344 
1345 
1346 
1347 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.arrayinit007.arrayinit007
1348 {
1349     // <Title>Array initializers</Title>
1350     // <Description>
1351     // </Description>
1352     // <RelatedBugs></RelatedBugs>
1353     //<Expects Status=success></Expects>
1354     // <Code>
1355 
1356     public class MainClass
1357     {
1358         [Fact]
DynamicCSharpRunTest()1359         public static void DynamicCSharpRunTest()
1360         {
1361             Assert.Equal(0, MainMethod());
1362         }
1363 
MainMethod()1364         public static int MainMethod()
1365         {
1366             dynamic attrs = new object[]
1367             {
1368             1, 2
1369             }
1370 
1371             ;
1372             dynamic dd = 1;
1373             var a = attrs[dd];
1374             if (a == 2)
1375                 return 0;
1376             return 1;
1377         }
1378     }
1379     // </Code>
1380 }
1381 
1382 
1383 
1384 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.boxing001.boxing001
1385 {
1386     public class Test
1387     {
1388         [Fact]
DynamicCSharpRunTest()1389         public static void DynamicCSharpRunTest()
1390         {
1391             Assert.Equal(0, MainMethod(null));
1392         }
1393 
MainMethod(string[] args)1394         public static int MainMethod(string[] args)
1395         {
1396             //int
1397             object o = int.MinValue;
1398             dynamic d = o;
1399             int i = (int)d;
1400             if (i != int.MinValue)
1401                 return 1;
1402             //short
1403             o = short.MaxValue;
1404             d = o;
1405             short s = (short)d;
1406             if (s != short.MaxValue)
1407                 return 1;
1408             //sbyte
1409             o = sbyte.MaxValue;
1410             d = o;
1411             sbyte sb = (sbyte)d;
1412             if (sb != sbyte.MaxValue)
1413                 return 1;
1414             //long
1415             o = long.MaxValue;
1416             d = o;
1417             long l = (long)d;
1418             if (l != long.MaxValue)
1419                 return 1;
1420             //byte
1421             o = byte.MaxValue;
1422             d = o;
1423             byte b = (byte)d;
1424             if (b != byte.MaxValue)
1425                 return 1;
1426             //ushort
1427             o = ushort.MaxValue;
1428             d = o;
1429             ushort us = (ushort)d;
1430             if (us != ushort.MaxValue)
1431                 return 1;
1432             //ulong
1433             o = ulong.MaxValue;
1434             d = o;
1435             ulong ul = (ulong)d;
1436             if (ul != ulong.MaxValue)
1437                 return 1;
1438             //uint
1439             o = uint.MinValue;
1440             d = o;
1441             uint ui = (uint)o;
1442             if (ui != uint.MinValue)
1443                 return 1;
1444             //char
1445             o = 'a';
1446             d = o;
1447             char c = (char)d;
1448             if (c != 'a')
1449                 return 1;
1450             //float
1451             o = float.Epsilon;
1452             d = o;
1453             float f = (float)d;
1454             if (f != float.Epsilon)
1455                 return 1;
1456             o = float.NegativeInfinity;
1457             d = o;
1458             f = (float)d;
1459             if (f != float.NegativeInfinity)
1460                 return 1;
1461             //double
1462             o = double.MaxValue;
1463             d = o;
1464             double dd = (double)d;
1465             if (dd != double.MaxValue)
1466                 return 1;
1467             //decimal
1468             o = decimal.MaxValue;
1469             d = o;
1470             decimal dc = (decimal)d;
1471             if (dc != decimal.MaxValue)
1472                 return 1;
1473             //bool
1474             o = true;
1475             d = o;
1476             bool bo = (bool)d;
1477             if (bo != true)
1478                 return 1;
1479             //UD enum
1480             o = myEnum.One;
1481             d = o;
1482             myEnum e = (myEnum)d;
1483             if (e != myEnum.One)
1484                 return 1;
1485             //UD struct
1486             o = new myStruct()
1487             {
1488                 field = 1
1489             }
1490 
1491             ;
1492             d = o;
1493             myStruct st = (myStruct)d;
1494             if (st.field != 1)
1495                 return 1;
1496             return 0;
1497         }
1498 
1499         public enum myEnum
1500         {
1501             One
1502         }
1503 
1504         public struct myStruct
1505         {
1506             public int field;
1507         }
1508     }
1509     // </Code>
1510 }
1511 
1512 
1513 
1514 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.boxing002.boxing002
1515 {
1516     public class Test
1517     {
1518         [Fact]
DynamicCSharpRunTest()1519         public static void DynamicCSharpRunTest()
1520         {
1521             Assert.Equal(0, MainMethod(null));
1522         }
1523 
MainMethod(string[] args)1524         public static int MainMethod(string[] args)
1525         {
1526             object o = null;
1527             dynamic d = null;
1528             //int
1529             d = int.MinValue;
1530             o = d;
1531             int i = (int)o;
1532             if (i != int.MinValue)
1533                 return 1;
1534             //short
1535             d = short.MaxValue;
1536             o = d;
1537             short s = (short)o;
1538             if (s != short.MaxValue)
1539                 return 1;
1540             //sbyte
1541             d = sbyte.MaxValue;
1542             o = d;
1543             sbyte sb = (sbyte)o;
1544             if (sb != sbyte.MaxValue)
1545                 return 1;
1546             //long
1547             d = long.MaxValue;
1548             o = d;
1549             long l = (long)o;
1550             if (l != long.MaxValue)
1551                 return 1;
1552             //byte
1553             d = byte.MaxValue;
1554             o = d;
1555             byte b = (byte)o;
1556             if (b != byte.MaxValue)
1557                 return 1;
1558             //ushort
1559             d = ushort.MaxValue;
1560             o = d;
1561             ushort us = (ushort)o;
1562             if (us != ushort.MaxValue)
1563                 return 1;
1564             //ulong
1565             d = ulong.MaxValue;
1566             o = d;
1567             ulong ul = (ulong)o;
1568             if (ul != ulong.MaxValue)
1569                 return 1;
1570             //uint
1571             d = uint.MinValue;
1572             o = d;
1573             uint ui = (uint)o;
1574             if (ui != uint.MinValue)
1575                 return 1;
1576             //char
1577             d = 'a';
1578             o = d;
1579             char c = (char)o;
1580             if (c != 'a')
1581                 return 1;
1582             //float
1583             d = float.Epsilon;
1584             o = d;
1585             float f = (float)o;
1586             if (f != float.Epsilon)
1587                 return 1;
1588             d = float.NegativeInfinity;
1589             o = d;
1590             f = (float)o;
1591             if (!float.IsNegativeInfinity(f))
1592                 return 1;
1593             //double
1594             d = double.MaxValue;
1595             o = d;
1596             double dd = (double)o;
1597             if (dd != double.MaxValue)
1598                 return 1;
1599             //decimal
1600             d = decimal.MaxValue;
1601             o = d;
1602             decimal dc = (decimal)o;
1603             if (dc != decimal.MaxValue)
1604                 return 1;
1605             //bool
1606             d = true;
1607             o = d;
1608             bool bo = (bool)o;
1609             if (bo != true)
1610                 return 1;
1611             //UD enum
1612             d = myEnum.One;
1613             o = d;
1614             myEnum e = (myEnum)o;
1615             if (e != myEnum.One)
1616                 return 1;
1617             //UD struct
1618             d = new myStruct()
1619             {
1620                 field = 1
1621             }
1622 
1623             ;
1624             o = d;
1625             myStruct st = (myStruct)o;
1626             if (st.field != 1)
1627                 return 1;
1628             return 0;
1629         }
1630 
1631         public enum myEnum
1632         {
1633             One
1634         }
1635 
1636         public struct myStruct
1637         {
1638             public int field;
1639         }
1640     }
1641     // </Code>
1642 }
1643 
1644 
1645 
1646 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.boxing003.boxing003
1647 {
1648     public class Test
1649     {
1650         [Fact]
DynamicCSharpRunTest()1651         public static void DynamicCSharpRunTest()
1652         {
1653             Assert.Equal(0, MainMethod(null));
1654         }
1655 
MainMethod(string[] args)1656         public static int MainMethod(string[] args)
1657         {
1658             //int
1659             object o = int.MinValue;
1660             dynamic d = o;
1661             if (!(d is int))
1662                 return 1;
1663             //short
1664             o = short.MaxValue;
1665             d = o;
1666             if (!(d is short))
1667                 return 1;
1668             //sbyte
1669             o = sbyte.MaxValue;
1670             d = o;
1671             if (!(d is sbyte))
1672                 return 1;
1673             //long
1674             o = long.MaxValue;
1675             d = o;
1676             if (!(d is long))
1677                 return 1;
1678             //byte
1679             o = byte.MaxValue;
1680             d = o;
1681             if (!(d is byte))
1682                 return 1;
1683             //ushort
1684             o = ushort.MaxValue;
1685             d = o;
1686             if (!(d is ushort))
1687                 return 1;
1688             //ulong
1689             o = ulong.MaxValue;
1690             d = o;
1691             if (!(d is ulong))
1692                 return 1;
1693             //uint
1694             o = uint.MinValue;
1695             d = o;
1696             if (!(d is uint))
1697                 return 1;
1698             //char
1699             o = 'a';
1700             d = o;
1701             if (!(d is char))
1702                 return 1;
1703             //float
1704             o = float.Epsilon;
1705             d = o;
1706             if (!(d is float))
1707                 return 1;
1708             //double
1709             o = double.MaxValue;
1710             d = o;
1711             if (!(d is double))
1712                 return 1;
1713             //decimal
1714             o = decimal.MaxValue;
1715             d = o;
1716             if (!(d is decimal))
1717                 return 1;
1718             //bool
1719             o = true;
1720             d = o;
1721             if (!(d is bool))
1722                 return 1;
1723             //UD enum
1724             o = myEnum.One;
1725             d = o;
1726             if (!(d is myEnum))
1727                 return 1;
1728             //UD struct
1729             o = new myStruct()
1730             {
1731                 field = 1
1732             }
1733 
1734             ;
1735             d = o;
1736             if (!(d is myStruct))
1737                 return 1;
1738             return 0;
1739         }
1740 
1741         public enum myEnum
1742         {
1743             One
1744         }
1745 
1746         public struct myStruct
1747         {
1748             public int field;
1749         }
1750     }
1751     // </Code>
1752 }
1753 
1754 
1755 
1756 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.boxing004.boxing004
1757 {
1758     public class Test
1759     {
1760         [Fact]
DynamicCSharpRunTest()1761         public static void DynamicCSharpRunTest()
1762         {
1763             Assert.Equal(0, MainMethod(null));
1764         }
1765 
MainMethod(string[] args)1766         public static int MainMethod(string[] args)
1767         {
1768             dynamic d = null;
1769             //int
1770             d = int.MinValue;
1771             int i = (int)d;
1772             if (i != int.MinValue)
1773                 return 1;
1774             //short
1775             d = short.MaxValue;
1776             short s = (short)d;
1777             if (s != short.MaxValue)
1778                 return 1;
1779             //sbyte
1780             d = sbyte.MaxValue;
1781             sbyte sb = (sbyte)d;
1782             if (sb != sbyte.MaxValue)
1783                 return 1;
1784             //long
1785             d = long.MaxValue;
1786             long l = (long)d;
1787             if (l != long.MaxValue)
1788                 return 1;
1789             //byte
1790             d = byte.MaxValue;
1791             byte b = (byte)d;
1792             if (b != byte.MaxValue)
1793                 return 1;
1794             //ushort
1795             d = ushort.MaxValue;
1796             ushort us = (ushort)d;
1797             if (us != ushort.MaxValue)
1798                 return 1;
1799             //ulong
1800             d = ulong.MaxValue;
1801             ulong ul = (ulong)d;
1802             if (ul != ulong.MaxValue)
1803                 return 1;
1804             //uint
1805             d = uint.MinValue;
1806             uint ui = (uint)d;
1807             if (ui != uint.MinValue)
1808                 return 1;
1809             //char
1810             d = 'a';
1811             char c = (char)d;
1812             if (c != 'a')
1813                 return 1;
1814             //float
1815             d = float.Epsilon;
1816             float f = (float)d;
1817             if (f != float.Epsilon)
1818                 return 1;
1819             d = float.NegativeInfinity;
1820             f = (float)d;
1821             if (!float.IsNegativeInfinity(f))
1822                 return 1;
1823             //double
1824             d = double.MaxValue;
1825             double dd = (double)d;
1826             if (dd != double.MaxValue)
1827                 return 1;
1828             //decimal
1829             d = decimal.MaxValue;
1830             decimal dc = (decimal)d;
1831             if (dc != decimal.MaxValue)
1832                 return 1;
1833             //bool
1834             d = true;
1835             bool bo = (bool)d;
1836             if (bo != true)
1837                 return 1;
1838             //UD enum
1839             d = myEnum.One;
1840             myEnum e = (myEnum)d;
1841             if (e != myEnum.One)
1842                 return 1;
1843             //UD struct
1844             d = new myStruct()
1845             {
1846                 field = 1
1847             }
1848 
1849             ;
1850             myStruct st = (myStruct)d;
1851             if (st.field != 1)
1852                 return 1;
1853             return 0;
1854         }
1855 
1856         public enum myEnum
1857         {
1858             One
1859         }
1860 
1861         public struct myStruct
1862         {
1863             public int field;
1864         }
1865     }
1866     // </Code>
1867 }
1868 
1869 
1870 
1871 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.boxing005.boxing005
1872 {
1873     // <Title>Boxing and unboxing</Title>
1874     // <Description>
1875     // Boxing to an object and unboxing from a dynamic
1876     // </Description>
1877     // <RelatedBugs></RelatedBugs>
1878     //<Expects Status=success></Expects>
1879     // <Code>
1880     public struct myStruct
1881     {
FooManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.boxing005.boxing005.myStruct1882         public void Foo()
1883         {
1884             Test.Status = 1;
1885         }
1886     }
1887 
1888     public class Test
1889     {
1890         public static int Status;
1891         [Fact]
DynamicCSharpRunTest()1892         public static void DynamicCSharpRunTest()
1893         {
1894             Assert.Equal(0, MainMethod(null));
1895         }
1896 
MainMethod(string[] args)1897         public static int MainMethod(string[] args)
1898         {
1899             dynamic d = new myStruct();
1900             d.Foo();
1901             if (Test.Status != 1)
1902                 return 1;
1903             return 0;
1904         }
1905     }
1906     // </Code>
1907 }
1908 
1909 
1910 
1911 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.boxing006.boxing006
1912 {
1913     // <Title>Boxing and unboxing</Title>
1914     // <Description>
1915     // Boxing to an object and unboxing from a dynamic
1916     // </Description>
1917     // <RelatedBugs></RelatedBugs>
1918     //<Expects Status=success></Expects>
1919     // <Code>
1920     public struct Value
1921     {
1922         public int X;
MutateXManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.boxing006.boxing006.Value1923         public void MutateX(int x)
1924         {
1925             this.X = x;
1926         }
1927     }
1928 
1929     public class Program
1930     {
1931 
DynamicCSharpRunTest()1932         public static void DynamicCSharpRunTest()
1933         {
1934             Assert.Equal(0, MainMethod());
1935         }
1936 
MainMethod()1937         public static int MainMethod()
1938         {
1939             Value s = default(Value);
1940             dynamic d = 5;
1941             s.MutateX(d);
1942             if (s.X != 5)
1943                 return 1;
1944             return 0;
1945         }
1946     }
1947     // </Code>
1948 }
1949 
1950 
1951 
1952 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.cast002.cast002
1953 {
1954     public class Test
1955     {
1956         [Fact]
DynamicCSharpRunTest()1957         public static void DynamicCSharpRunTest()
1958         {
1959             Assert.Equal(0, MainMethod(null));
1960         }
1961 
MainMethod(string[] args)1962         public static int MainMethod(string[] args)
1963         {
1964             int i1 = 10;
1965             int i2 = (dynamic)(-10);
1966             return 0;
1967         }
1968     }
1969     // </Code>
1970 }
1971 
1972 
1973 
1974 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.collectioninit001.collectioninit001
1975 {
1976     // <Title>Collection initializers</Title>
1977     // <Description>
1978     // </Description>
1979     // <RelatedBugs></RelatedBugs>
1980     //<Expects Status=success></Expects>
1981     // <Code>
1982     using System.Collections.Generic;
1983 
1984     public class Test
1985     {
1986         [Fact]
DynamicCSharpRunTest()1987         public static void DynamicCSharpRunTest()
1988         {
1989             Assert.Equal(0, MainMethod(null));
1990         }
1991 
MainMethod(string[] args)1992         public static int MainMethod(string[] args)
1993         {
1994             List<dynamic> myList = new List<dynamic>()
1995             {
1996             1, 2, "Fooo", long.MaxValue
1997             }
1998 
1999             ;
2000             if (myList.Count != 4)
2001                 return 1;
2002             if ((int)myList[0] != 1)
2003                 return 1;
2004             if ((int)myList[1] != 2)
2005                 return 1;
2006             if ((string)myList[2] != "Fooo")
2007                 return 1;
2008             if ((long)myList[3] != long.MaxValue)
2009                 return 1;
2010             return 0;
2011         }
2012     }
2013     // </Code>
2014 }
2015 
2016 
2017 
2018 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.collectioninit002.collectioninit002
2019 {
2020     // <Title>Collection initializers</Title>
2021     // <Description>
2022     // </Description>
2023     // <RelatedBugs></RelatedBugs>
2024     //<Expects Status=success></Expects>
2025     // <Code>
2026     using System.Collections.Generic;
2027 
2028     public class Test
2029     {
2030         [Fact]
DynamicCSharpRunTest()2031         public static void DynamicCSharpRunTest()
2032         {
2033             Assert.Equal(0, MainMethod(null));
2034         }
2035 
MainMethod(string[] args)2036         public static int MainMethod(string[] args)
2037         {
2038             object o = 2;
2039             dynamic d = o;
2040             List<dynamic> myList = new List<dynamic>()
2041             {
2042             o, d
2043             }
2044 
2045             ;
2046             return 0;
2047         }
2048     }
2049     // </Code>
2050 }
2051 
2052 
2053 
2054 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.collectioninit003.collectioninit003
2055 {
2056     // <Title>Collection initializers</Title>
2057     // <Description>
2058     // </Description>
2059     // <RelatedBugs></RelatedBugs>
2060     //<Expects Status=success></Expects>
2061     // <Code>
2062     using System.Collections.Generic;
2063 
2064     public class Test
2065     {
2066 
DynamicCSharpRunTest()2067         public static void DynamicCSharpRunTest()
2068         {
2069             Assert.Equal(0, MainMethod(null));
2070         }
2071 
MainMethod(string[] args)2072         public static int MainMethod(string[] args)
2073         {
2074             List<dynamic> myList = new List<dynamic>()
2075             {
2076             new
2077             {
2078             Name = "Foo", Value = 3
2079             }
2080             }
2081 
2082             ;
2083             if ((int)myList[0].Value != 3)
2084                 return 1;
2085             return 0;
2086         }
2087     }
2088     // </Code>
2089 }
2090 
2091 
2092 
2093 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.collectioninit004.collectioninit004
2094 {
2095     // <Title>Collection initializers</Title>
2096     // <Description>
2097     // </Description>
2098     // <RelatedBugs></RelatedBugs>
2099     //<Expects Status=success></Expects>
2100     // <Code>
2101     using System.Collections.Generic;
2102 
2103     public class Test
2104     {
2105         [Fact]
DynamicCSharpRunTest()2106         public static void DynamicCSharpRunTest()
2107         {
2108             Assert.Equal(0, MainMethod(null));
2109         }
2110 
MainMethod(string[] args)2111         public static int MainMethod(string[] args)
2112         {
2113             List<dynamic> myList = new List<object>()
2114             {
2115             3
2116             }
2117 
2118             ;
2119             return 0;
2120         }
2121     }
2122     // </Code>
2123 }
2124 
2125 
2126 
2127 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.collectioninit005.collectioninit005
2128 {
2129     // <Title>Collection initializers</Title>
2130     // <Description>
2131     // </Description>
2132     // <RelatedBugs></RelatedBugs>
2133     //<Expects Status=success></Expects>
2134     // <Code>
2135     using System.Collections.Generic;
2136 
2137     public class Test
2138     {
2139         [Fact]
DynamicCSharpRunTest()2140         public static void DynamicCSharpRunTest()
2141         {
2142             Assert.Equal(0, MainMethod(null));
2143         }
2144 
MainMethod(string[] args)2145         public static int MainMethod(string[] args)
2146         {
2147             List<object> myList = new List<dynamic>()
2148             {
2149             3
2150             }
2151 
2152             ;
2153             return 0;
2154         }
2155     }
2156     // </Code>
2157 }
2158 
2159 
2160 
2161 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.collectioninit006.collectioninit006
2162 {
2163     // <Title>Collection initializers</Title>
2164     // <Description>
2165     // </Description>
2166     // <RelatedBugs></RelatedBugs>
2167     //<Expects Status=success></Expects>
2168     // <Code>
2169     using System.Collections.Generic;
2170 
2171     public class Test
2172     {
2173         [Fact]
DynamicCSharpRunTest()2174         public static void DynamicCSharpRunTest()
2175         {
2176             Assert.Equal(0, MainMethod(null));
2177         }
2178 
MainMethod(string[] args)2179         public static int MainMethod(string[] args)
2180         {
2181             dynamic d = 3;
2182             List<object> myList = new List<object>()
2183             {
2184             d
2185             }
2186 
2187             ;
2188             if ((int)myList[0] != 3)
2189                 return 1;
2190             return 0;
2191         }
2192     }
2193     // </Code>
2194 }
2195 
2196 
2197 
2198 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.collectioninit007.collectioninit007
2199 {
2200     // <Title>Collection initializers</Title>
2201     // <Description>
2202     // </Description>
2203     // <RelatedBugs></RelatedBugs>
2204     //<Expects Status=success></Expects>
2205     // <Code>
2206     using System.Collections.Generic;
2207 
2208     public class Test
2209     {
2210         [Fact]
DynamicCSharpRunTest()2211         public static void DynamicCSharpRunTest()
2212         {
2213             Assert.Equal(0, MainMethod(null));
2214         }
2215 
MainMethod(string[] args)2216         public static int MainMethod(string[] args)
2217         {
2218             object o = 3;
2219             List<dynamic> myList = new List<dynamic>()
2220             {
2221             o
2222             }
2223 
2224             ;
2225             if ((int)myList[0] != 3)
2226                 return 1;
2227             return 0;
2228         }
2229     }
2230     // </Code>
2231 }
2232 
2233 
2234 
2235 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.collectioninit008.collectioninit008
2236 {
2237     // <Title>Collection initializers</Title>
2238     // <Description>
2239     // </Description>
2240     // <RelatedBugs></RelatedBugs>
2241     //<Expects Status=success></Expects>
2242     // <Code>
2243     using System.Collections.Generic;
2244     using System.Text;
2245 
2246     public class A
2247     {
2248         [Fact]
DynamicCSharpRunTest()2249         public static void DynamicCSharpRunTest()
2250         {
2251             Assert.Equal(0, MainMethod());
2252         }
2253 
MainMethod()2254         public static int MainMethod()
2255         {
2256             dynamic a = new A
2257             {
2258                 S =
2259             {
2260             Length = 10
2261             }
2262 
2263             ,
2264                 X =
2265             {
2266             1, 2, 3
2267             }
2268             }
2269 
2270             ;
2271             return 0;
2272         }
2273 
2274         public dynamic S = new StringBuilder();
2275         public dynamic X = new List<int>();
2276     }
2277     // </Code>
2278 }
2279 
2280 
2281 
2282 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.collectioninit009.collectioninit009
2283 {
2284     // <Title>Collection initializers</Title>
2285     // <Description>
2286     // </Description>
2287     // <RelatedBugs></RelatedBugs>
2288     //<Expects Status=success></Expects>
2289     // <Code>
2290     //<Expects Status=warning>\(15,9\).*CS0219</Expects>
2291     using System;
2292 
2293     public class Test
2294     {
2295         [Fact]
DynamicCSharpRunTest()2296         public static void DynamicCSharpRunTest()
2297         {
2298             Assert.Equal(0, MainMethod());
2299         }
2300 
MainMethod()2301         public static int MainMethod()
2302         {
2303             //array initializer
2304             dynamic d = 3;
2305             int rez = 0;
2306             Collect c = new Collect()
2307             {
2308             1, 3L, "goo", d
2309             }
2310 
2311             ;
2312             if (Collect.Status != 8)
2313                 return 1;
2314             return 0;
2315         }
2316     }
2317 
2318     public class Collect : System.Collections.IEnumerable
2319     {
2320         public static int Status;
Add(int x)2321         public void Add(int x)
2322         {
2323             Collect.Status += 1;
2324         }
2325 
Add(long x)2326         public void Add(long x)
2327         {
2328             Collect.Status += 2;
2329         }
2330 
Add(string x)2331         public void Add(string x)
2332         {
2333             Collect.Status += 4;
2334         }
2335 
Add(dynamic x)2336         public void Add(dynamic x)
2337         {
2338             Collect.Status += 8;
2339         }
2340 
GetEnumerator()2341         public System.Collections.IEnumerator GetEnumerator()
2342         {
2343             throw new NotImplementedException();
2344         }
2345     }
2346     // </Code>
2347 }
2348 
2349 
2350 
2351 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.dlgate001.dlgate001
2352 {
2353     public class Test
2354     {
Foo(object o)2355         public delegate void Foo(object o);
2356         [Fact]
DynamicCSharpRunTest()2357         public static void DynamicCSharpRunTest()
2358         {
2359             Assert.Equal(0, MainMethod(null));
2360         }
2361 
MainMethod(string[] args)2362         public static int MainMethod(string[] args)
2363         {
2364             Foo f = delegate (dynamic d)
2365             {
2366             }
2367 
2368             ;
2369             f(3);
2370             return 0;
2371         }
2372     }
2373     // </Code>
2374 }
2375 
2376 
2377 
2378 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.dlgate002.dlgate002
2379 {
2380     public class Test
2381     {
Foo(dynamic o)2382         public delegate void Foo(dynamic o);
2383         [Fact]
DynamicCSharpRunTest()2384         public static void DynamicCSharpRunTest()
2385         {
2386             Assert.Equal(0, MainMethod(null));
2387         }
2388 
MainMethod(string[] args)2389         public static int MainMethod(string[] args)
2390         {
2391             Foo f = delegate (object d)
2392             {
2393             }
2394 
2395             ;
2396             f(2);
2397             return 0;
2398         }
2399     }
2400     // </Code>
2401 }
2402 
2403 
2404 
2405 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.dlgate003.dlgate003
2406 {
2407     // <Title>Delegates</Title>
2408     // <Description>
2409     // </Description>
2410     // <RelatedBugs></RelatedBugs>
2411     //<Expects Status=success></Expects>
2412     // <Code>
2413     public class Bar
2414     {
Foo()2415         public int Foo()
2416         {
2417             return 0;
2418         }
2419     }
2420 
2421     public class Test
2422     {
Foo()2423         public delegate dynamic Foo();
2424         [Fact]
DynamicCSharpRunTest()2425         public static void DynamicCSharpRunTest()
2426         {
2427             Assert.Equal(0, MainMethod(null));
2428         }
2429 
MainMethod(string[] args)2430         public static int MainMethod(string[] args)
2431         {
2432             Foo f = delegate ()
2433             {
2434                 return new Bar();
2435             }
2436 
2437             ;
2438             return f().Foo();
2439         }
2440     }
2441     // </Code>
2442 }
2443 
2444 
2445 
2446 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.dlgate004.dlgate004
2447 {
2448     // <Title>Delegates</Title>
2449     // <Description>
2450     // </Description>
2451     // <RelatedBugs></RelatedBugs>
2452     //<Expects Status=success></Expects>
2453     // <Code>
2454     public class Bar
2455     {
Foo()2456         public int Foo()
2457         {
2458             return 0;
2459         }
2460     }
2461 
2462     public class Test
2463     {
Foo()2464         public delegate dynamic Foo();
2465         [Fact]
DynamicCSharpRunTest()2466         public static void DynamicCSharpRunTest()
2467         {
2468             Assert.Equal(0, MainMethod(null));
2469         }
2470 
MainMethod(string[] args)2471         public static int MainMethod(string[] args)
2472         {
2473             Foo f = delegate ()
2474             {
2475                 return new Bar();
2476             }
2477 
2478             ;
2479             return (int)f().Foo();
2480         }
2481     }
2482     // </Code>
2483 }
2484 
2485 
2486 
2487 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.dlgate005.dlgate005
2488 {
2489     // <Title>Delegates</Title>
2490     // <Description>
2491     // </Description>
2492     // <RelatedBugs></RelatedBugs>
2493     //<Expects Status=success></Expects>
2494     // <Code>
2495     public class Bar
2496     {
Foo()2497         public int Foo()
2498         {
2499             return 0;
2500         }
2501     }
2502 
2503     public class Test
2504     {
Foo(dynamic o)2505         public delegate void Foo(dynamic o);
2506         public static event Foo myEvent;
2507         private static int s_status;
2508         [Fact]
DynamicCSharpRunTest()2509         public static void DynamicCSharpRunTest()
2510         {
2511             Assert.Equal(0, MainMethod(null));
2512         }
2513 
MainMethod(string[] args)2514         public static int MainMethod(string[] args)
2515         {
2516             myEvent += myFoo;
2517             myEvent(new Bar());
2518             if (Test.s_status == 0)
2519                 return 0;
2520             else
2521                 return 1;
2522         }
2523 
myFoo(dynamic d)2524         public static void myFoo(dynamic d)
2525         {
2526             Test.s_status = (int)d.Foo();
2527         }
2528     }
2529     // </Code>
2530 }
2531 
2532 
2533 
2534 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.dlgate007.dlgate007
2535 {
2536     // <Title>Delegates</Title>
2537     // <Description>
2538     // </Description>
2539     // <RelatedBugs></RelatedBugs>
2540     //<Expects Status=success></Expects>
2541     // <Code>
2542     public class Bar
2543     {
Foo()2544         public int Foo()
2545         {
2546             return 0;
2547         }
2548     }
2549 
2550     public class Test
2551     {
Foo(object o)2552         public delegate void Foo(object o);
2553         public static event Foo myEvent;
2554         private static int s_status;
2555         [Fact]
DynamicCSharpRunTest()2556         public static void DynamicCSharpRunTest()
2557         {
2558             Assert.Equal(0, MainMethod(null));
2559         }
2560 
MainMethod(string[] args)2561         public static int MainMethod(string[] args)
2562         {
2563             myEvent += myFoo;
2564             myEvent(new Bar());
2565             if (Test.s_status == 0)
2566                 return 0;
2567             else
2568                 return 1;
2569         }
2570 
myFoo(dynamic d)2571         public static void myFoo(dynamic d)
2572         {
2573             Test.s_status = (int)d.Foo();
2574         }
2575     }
2576     // </Code>
2577 }
2578 
2579 
2580 
2581 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.dlgate008lib.dlgate008lib
2582 {
2583     public class Test
2584     {
M1(ref int p1)2585         public void M1(ref int p1)
2586         {
2587         }
2588 
2589 
DynamicCSharpRunTest()2590         public static void DynamicCSharpRunTest()
2591         {
2592             Assert.Equal(0, MainMethod());
2593         }
2594 
MainMethod()2595         public static int MainMethod()
2596         {
2597             dynamic dobj = new Test();
2598             int i1 = 10;
2599             int i2 = 20;
2600             dobj.M1(ref i1);
2601             dobj.M1(ref i2);
2602             return 0;
2603         }
2604     }
2605     // </Code>
2606 }
2607 
2608 
2609 
2610 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.evnt001.evnt001
2611 {
2612     // <Title>Delegates</Title>
2613     // <Description></Description>
2614     // <RelatedBugs></RelatedBugs>
2615     // <Expects Status=success></Expects>
2616     // <Code>
2617     using System;
2618 
MyEventHandler1(object sender, EventArgs e)2619     public delegate void MyEventHandler1(object sender, EventArgs e);
MyEventHandler2(dynamic sender)2620     public delegate void MyEventHandler2(dynamic sender);
MyEventHandler3(dynamic d1, dynamic d2, EventArgs e)2621     public delegate void MyEventHandler3(dynamic d1, dynamic d2, EventArgs e);
2622     public class MyEvent
2623     {
2624         public event MyEventHandler1 myEvent1;
2625         internal event MyEventHandler2 myEvent2;
2626         public event MyEventHandler3 myEvent3;
Fire1(EventArgs e)2627         public void Fire1(EventArgs e)
2628         {
2629             if (myEvent1 != null)
2630                 myEvent1(this, e);
2631         }
2632 
Fire2(EventArgs e)2633         internal void Fire2(EventArgs e)
2634         {
2635             if (myEvent2 != null)
2636                 myEvent2(this);
2637         }
2638 
Fire3(EventArgs e)2639         internal void Fire3(EventArgs e)
2640         {
2641             if (myEvent3 != null)
2642                 myEvent3(this, null, e);
2643         }
2644     }
2645 
2646     public class Test
2647     {
2648         private int _result = -1;
EventReceiver1(dynamic sender, EventArgs e)2649         public void EventReceiver1(dynamic sender, EventArgs e)
2650         {
2651             _result = 1;
2652         }
2653 
EventReceiver2(object sender)2654         private void EventReceiver2(object sender)
2655         {
2656             _result = 2;
2657         }
2658 
EventReceiver3(object d1, dynamic d2, EventArgs e)2659         internal void EventReceiver3(object d1, dynamic d2, EventArgs e)
2660         {
2661             _result = 3;
2662         }
2663 
2664         [Fact]
DynamicCSharpRunTest()2665         public static void DynamicCSharpRunTest()
2666         {
2667             Assert.Equal(0, MainMethod());
2668         }
2669 
MainMethod()2670         public static int MainMethod()
2671         {
2672             // Console.ForegroundColor = ConsoleColor.White;
2673             // Console.BackgroundColor = ConsoleColor.DarkRed;
2674             Test t = new Test();
2675             return t.RunTest() ? 0 : 1;
2676         }
2677 
RunTest()2678         public bool RunTest()
2679         {
2680             bool ret = true;
2681             MyEvent me = new MyEvent();
2682             // myEvent1 +1
2683             me.myEvent1 += new MyEventHandler1(EventReceiver1);
2684             me.Fire1(new EventArgs());
2685             ret = (1 == _result);
2686             // myEvent1 +1 => 2
2687             me.myEvent1 += new MyEventHandler1(EventReceiver1);
2688             me.Fire1(new EventArgs());
2689             ret = (1 == _result);
2690             // myEvent1 -1 => 1
2691             me.myEvent1 -= new MyEventHandler1(EventReceiver1);
2692             me.Fire1(new EventArgs());
2693             ret = (1 == _result);
2694             // myEvent1 -1 => 0
2695             _result = 0;
2696             me.myEvent1 -= new MyEventHandler1(EventReceiver1);
2697             me.Fire1(new EventArgs());
2698             ret = (0 == _result);
2699             me.myEvent2 += new MyEventHandler2(EventReceiver2);
2700             me.myEvent2 += new MyEventHandler2(EventReceiver2);
2701             me.myEvent2 += new MyEventHandler2(EventReceiver2);
2702             me.Fire2(new EventArgs());
2703             ret &= (2 == _result);
2704             me.myEvent2 -= new MyEventHandler2(EventReceiver2);
2705             me.myEvent2 -= new MyEventHandler2(EventReceiver2);
2706             me.Fire2(new EventArgs());
2707             ret &= (2 == _result);
2708             me.myEvent3 += new MyEventHandler3(EventReceiver3);
2709             me.Fire3(new EventArgs());
2710             ret &= (3 == _result);
2711             _result = 0;
2712             me.myEvent3 -= new MyEventHandler3(EventReceiver3);
2713             me.Fire3(new EventArgs());
2714             ret &= (0 == _result);
2715             return ret;
2716         }
2717     }
2718     // </Code>
2719 }
2720 
2721 
2722 
2723 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.evnt002.evnt002
2724 {
2725     // <Title>Delegates</Title>
2726     // <Description></Description>
2727     // <RelatedBugs></RelatedBugs>
2728     // <Expects Status=success></Expects>
2729     // <Code>
2730     using System;
2731 
MyEventHandler1(dynamic sender, EventArgs e)2732     public delegate void MyEventHandler1(dynamic sender, EventArgs e);
MyEventHandler2(dynamic sender)2733     public delegate void MyEventHandler2(dynamic sender);
MyEventHandler3(object d1, dynamic d2, EventArgs e)2734     public delegate void MyEventHandler3(object d1, dynamic d2, EventArgs e);
2735     abstract public class MyEvent1
2736     {
2737         abstract internal event MyEventHandler1 myEvent1;
2738         virtual internal event MyEventHandler2 myEvent2;
2739         public event MyEventHandler3 myEvent3;
Fire2(EventArgs e)2740         internal void Fire2(EventArgs e)
2741         {
2742             if (myEvent2 != null)
2743                 myEvent2(this);
2744         }
2745 
Fire3(EventArgs e)2746         internal void Fire3(EventArgs e)
2747         {
2748             if (myEvent3 != null)
2749                 myEvent3(this, null, e);
2750         }
2751     }
2752 
2753     public class MyEvent2 : MyEvent1
2754     {
2755         override internal event MyEventHandler1 myEvent1;
2756         new internal event MyEventHandler2 myEvent2;
2757         // public event MyEventHandler3 myEvent3;
Fire1(EventArgs e)2758         public void Fire1(EventArgs e)
2759         {
2760             if (myEvent1 != null)
2761                 myEvent1(this, e);
2762         }
2763 
Fire2(EventArgs e)2764         new internal void Fire2(EventArgs e)
2765         {
2766             if (myEvent2 != null)
2767                 myEvent2(this);
2768         }
2769     }
2770 
2771     public class Test
2772     {
2773         private int _result = -1;
EventReceiver1(object sender, EventArgs e)2774         public void EventReceiver1(object sender, EventArgs e)
2775         {
2776             _result = 1;
2777         }
2778 
EventReceiver21(dynamic sender)2779         private void EventReceiver21(dynamic sender)
2780         {
2781             _result = 21;
2782         }
2783 
EventReceiver22(object sender)2784         private void EventReceiver22(object sender)
2785         {
2786             _result = 22;
2787         }
2788 
EventReceiver3(dynamic d1, dynamic d2, EventArgs e)2789         internal void EventReceiver3(dynamic d1, dynamic d2, EventArgs e)
2790         {
2791             _result = 3;
2792         }
2793 
2794         [Fact]
DynamicCSharpRunTest()2795         public static void DynamicCSharpRunTest()
2796         {
2797             Assert.Equal(0, MainMethod());
2798         }
2799 
MainMethod()2800         public static int MainMethod()
2801         {
2802             // Console.ForegroundColor = ConsoleColor.White;
2803             // Console.BackgroundColor = ConsoleColor.DarkRed;
2804             Test t = new Test();
2805             return t.RunTest() ? 0 : 1;
2806         }
2807 
RunTest()2808         public bool RunTest()
2809         {
2810             bool ret = true;
2811             MyEvent1 me1 = new MyEvent2();
2812             MyEvent2 me = new MyEvent2();
2813             // myEvent1 +1
2814             me.myEvent1 += new MyEventHandler1(EventReceiver1);
2815             me.Fire1(new EventArgs());
2816             ret = (1 == _result);
2817             // myEvent1 +1 => 2
2818             _result = 0;
2819             me.myEvent1 += new MyEventHandler1(EventReceiver1);
2820             me.Fire1(new EventArgs());
2821             ret = (1 == _result);
2822             // myEvent1 -1 => 1
2823             _result = 0;
2824             me.myEvent1 -= new MyEventHandler1(EventReceiver1);
2825             me.Fire1(new EventArgs());
2826             ret = (1 == _result);
2827             // myEvent1 -1 => 0
2828             _result = 0;
2829             me.myEvent1 -= new MyEventHandler1(EventReceiver1);
2830             me.Fire1(new EventArgs());
2831             ret = (0 == _result);
2832             me.myEvent2 += new MyEventHandler2(EventReceiver21);
2833             me.myEvent2 += new MyEventHandler2(EventReceiver21);
2834             me.myEvent2 += new MyEventHandler2(EventReceiver21);
2835             me.Fire2(new EventArgs());
2836             ret &= (21 == _result);
2837             _result = 0;
2838             me.myEvent2 -= new MyEventHandler2(EventReceiver21);
2839             me.myEvent2 -= new MyEventHandler2(EventReceiver21);
2840             me.Fire2(new EventArgs());
2841             ret &= (21 == _result);
2842             me1.myEvent2 += new MyEventHandler2(EventReceiver22);
2843             me1.myEvent2 += new MyEventHandler2(EventReceiver22);
2844             me1.Fire2(new EventArgs());
2845             ret &= (22 == _result);
2846             _result = 0;
2847             me1.myEvent2 -= new MyEventHandler2(EventReceiver22);
2848             me1.myEvent2 -= new MyEventHandler2(EventReceiver22);
2849             me1.Fire2(new EventArgs());
2850             ret &= (0 == _result);
2851             me.myEvent3 += new MyEventHandler3(EventReceiver3);
2852             me.Fire3(new EventArgs());
2853             ret &= (3 == _result);
2854             _result = 0;
2855             me.myEvent3 -= new MyEventHandler3(EventReceiver3);
2856             me.Fire3(new EventArgs());
2857             ret &= (0 == _result);
2858             return ret;
2859         }
2860     }
2861     // </Code>
2862 }
2863 
2864 
2865 
2866 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.evnt003.evnt003
2867 {
2868     // <Title>Delegates</Title>
2869     // <Description></Description>
2870     // <RelatedBugs></RelatedBugs>
2871     //<Expects Status=warning>\(12,31\).*CS0067</Expects>
2872     // <Expects Status=success></Expects>
2873     // <Code>
2874     using System;
2875 
2876     public class A
2877     {
2878         public event EventHandler E;
EventH(object sender, EventArgs e)2879         public static void EventH(object sender, EventArgs e)
2880         {
2881         }
2882 
2883 
DynamicCSharpRunTest()2884         public static void DynamicCSharpRunTest()
2885         {
2886             Assert.Equal(0, MainMethod());
2887         }
2888 
MainMethod()2889         public static int MainMethod()
2890         {
2891             dynamic x = new A();
2892             x.E += new EventHandler(EventH);
2893             try
2894             {
2895                 x.E.ToString();
2896             }
2897             catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e) // Should Not Ex
2898             {
2899                 return 1;
2900             }
2901 
2902             return 0;
2903         }
2904     }
2905     // </Code>
2906 }
2907 
2908 
2909 
2910 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.evnt004.evnt004
2911 {
2912     // <Title>Delegates</Title>
2913     // <Description></Description>
2914     // <RelatedBugs></RelatedBugs>
2915     //<Expects Status=warning>\(12,31\).*CS0067</Expects>
2916     // <Expects Status=success></Expects>
2917     // <Code>
2918     using System;
2919 
2920     public class A
2921     {
2922         public event EventHandler E;
2923 
2924 
DynamicCSharpRunTest()2925         public static void DynamicCSharpRunTest()
2926         {
2927             Assert.Equal(0, MainMethod());
2928         }
2929 
MainMethod()2930         public static int MainMethod()
2931         {
2932             dynamic x = new A();
2933             // what to expect:
2934             // We should disallow access to events as properties under all circumstances.
2935             // Then, the rule is simple: dynamic dispatch on a dynamic argument never resolves to a private member.
2936             try
2937             {
2938                 x.E();
2939             }
2940             catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
2941             {
2942                 if (ErrorVerifier.Verify(RuntimeErrorId.NullReferenceOnMemberException, e.Message))
2943                     return 0;
2944             }
2945 
2946             return 1;
2947         }
2948     }
2949     // </Code>
2950 }
2951 
2952 
2953 
2954 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.evnt006.evnt006
2955 {
2956     // <Title>Delegates</Title>
2957     // <Description>Extended scenarios - event should not resolved as property </Description>
2958     // <RelatedBugs></RelatedBugs>
2959     //<Expects Status=warning>\(22,33\).*CS0067</Expects>
2960     //<Expects Status=warning>\(23,34\).*CS0067</Expects>
2961     //<Expects Status=warning>\(24,38\).*CS0067</Expects>
2962     //<Expects Status=warning>\(25,39\).*CS0067</Expects>
2963     //<Expects Status=warning>\(26,42\).*CS0067</Expects>
2964     // <Expects Status=success></Expects>
2965     // <Code>
2966     using System;
2967 
2968     abstract public class A1
2969     {
2970         internal abstract event EventHandler E5;
2971     }
2972 
2973     public class A2 : A1
2974     {
2975         internal event EventHandler E1;
2976         protected event EventHandler E2;
2977         public static event EventHandler E3;
2978         public virtual event EventHandler E4;
2979         internal override event EventHandler E5;
2980         private event EventHandler E6;
2981         /// <summary>
2982         /// not related to prop, just more negative scenarios
2983         /// </summary>
2984         /// <returns></returns>
M1()2985         public bool M1()
2986         {
2987             try
2988             {
2989                 E6.ToString();
2990             }
2991             catch (System.NullReferenceException)
2992             {
2993                 return true;
2994             }
2995 
2996             return false;
2997         }
2998 
2999         /// <summary>
3000         /// not related to prop, just more negative scenarios
3001         /// </summary>
3002         /// <returns></returns>
M2()3003         public bool M2()
3004         {
3005             try
3006             {
3007                 E6(null, null);
3008             }
3009             catch (System.NullReferenceException)
3010             {
3011                 return true;
3012             }
3013 
3014             return false;
3015         }
3016 
3017 
DynamicCSharpRunTest()3018         public static void DynamicCSharpRunTest()
3019         {
3020             Assert.Equal(0, MainMethod());
3021         }
3022 
MainMethod()3023         public static int MainMethod()
3024         {
3025             dynamic d = new A2();
3026             bool ret = d.M1();
3027             ret &= d.M2();
3028             for (int i = 1; i < 7; i++)
3029             {
3030                 ret &= CallEvent(d, i);
3031             }
3032 
3033             d = new A3();
3034             ret &= d.M3();
3035             for (int i = 1; i < 7; i++)
3036             {
3037                 ret &= CallEvent(d, i);
3038             }
3039 
3040             return ret ? 0 : 1;
3041         }
3042 
CallEvent(dynamic d, int count)3043         public static bool CallEvent(dynamic d, int count)
3044         {
3045             try
3046             {
3047                 switch (count)
3048                 {
3049                     case 1:
3050                         d.E1();
3051                         break;
3052                     case 2:
3053                         d.E2().ToString();
3054                         break;
3055                     case 3:
3056                         d.E3();
3057                         break;
3058                     case 4:
3059                         d.E4.ToString();
3060                         break;
3061                     case 5:
3062                         d.E5();
3063                         break;
3064                     case 6:
3065                         d.E6.ToString();
3066                         break;
3067                 }
3068             }
3069             catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
3070             {
3071                 // new errMsg - Delegate 'EventHandler' does not take '0' arguments
3072                 if (ErrorVerifier.Verify(ErrorMessageId.BadDelArgCount, e.Message, "EventHandler", "0") || ErrorVerifier.Verify(ErrorMessageId.ObjectProhibited, e.Message, "A2.E3") || ErrorVerifier.Verify(RuntimeErrorId.NullReferenceOnMemberException, e.Message))
3073                     return true;
3074             }
3075 
3076             return false;
3077         }
3078     }
3079 
3080     public class A3 : A2
3081     {
3082         private new event EventHandler E1;
3083         public override event EventHandler E4;
3084         /// <summary>
3085         /// not related to prop, just more negative scenarios
3086         /// </summary>
3087         /// <returns></returns>
M3()3088         public bool M3()
3089         {
3090             bool ret = true;
3091             try
3092             {
3093                 E1.ToString();
3094             }
3095             catch (System.NullReferenceException)
3096             {
3097                 goto L1;
3098             }
3099 
3100             ret = false;
3101         L1:
3102             try
3103             {
3104                 E1(null, null);
3105             }
3106             catch (System.NullReferenceException)
3107             {
3108                 goto L2;
3109             }
3110 
3111             ret = false;
3112         L2:
3113             try
3114             {
3115                 E4.ToString();
3116             }
3117             catch (System.NullReferenceException)
3118             {
3119                 goto L3;
3120             }
3121 
3122             ret = false;
3123         L3:
3124             try
3125             {
3126                 E4(null, null);
3127             }
3128             catch (System.NullReferenceException)
3129             {
3130                 return ret;
3131             }
3132 
3133             return false;
3134         }
3135     }
3136     // </Code>
3137 }
3138 
3139 
3140 
3141 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.evnt008.evnt008
3142 {
3143     // <Title>Event</Title>
3144     // <Description>Add null to an event</Description>
3145     // <RelatedBugs></RelatedBugs>
3146     // <Expects Status=success></Expects>
3147     // <Code>
3148     //<Expects Status=warning>\(13,23\).*CS0067</Expects>
3149 
3150     public class X
3151     {
MyEvent()3152         public delegate void MyEvent();
3153         public event MyEvent XX;
3154         [Fact]
DynamicCSharpRunTest()3155         public static void DynamicCSharpRunTest()
3156         {
3157             Assert.Equal(0, MainMethod());
3158         }
3159 
MainMethod()3160         public static int MainMethod()
3161         {
3162             dynamic x = new X();
3163             x.XX += null;
3164             return 0;
3165         }
3166     }
3167     // </Code>
3168 }
3169 
3170 
3171 
3172 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.explicit001.explicit001
3173 {
3174     public class Test
3175     {
3176         [Fact]
DynamicCSharpRunTest()3177         public static void DynamicCSharpRunTest()
3178         {
3179             Assert.Equal(0, MainMethod(null));
3180         }
3181 
MainMethod(string[] args)3182         public static int MainMethod(string[] args)
3183         {
3184             object o = null;
3185             dynamic d = null;
3186             int x = int.MaxValue;
3187             o = (dynamic)x;
3188             if ((int)o != int.MaxValue)
3189                 return 1;
3190             d = (object)x;
3191             if ((int)d != int.MaxValue)
3192                 return 1;
3193             myClass c = new myClass()
3194             {
3195                 Field = 2
3196             }
3197 
3198             ;
3199             o = (dynamic)c;
3200             if (((myClass)o).Field != 2)
3201                 return 1;
3202             d = (object)c;
3203             if (((myClass)d).Field != 2)
3204                 return 1;
3205             return 0;
3206         }
3207 
3208         public class myClass
3209         {
3210             public int Field;
3211         }
3212     }
3213     // </Code>
3214 }
3215 
3216 
3217 
3218 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.explicit002.explicit002
3219 {
3220     public class Test
3221     {
3222         [Fact]
DynamicCSharpRunTest()3223         public static void DynamicCSharpRunTest()
3224         {
3225             Assert.Equal(0, MainMethod(null));
3226         }
3227 
MainMethod(string[] args)3228         public static int MainMethod(string[] args)
3229         {
3230             dynamic d = (dynamic)(object)(int)1;
3231             if ((int)d != 1)
3232                 return 1;
3233             d = (object)(dynamic)1;
3234             if ((int)d != 1)
3235                 return 1;
3236             return 0;
3237         }
3238     }
3239     // </Code>
3240 }
3241 
3242 
3243 
3244 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.explicit003.explicit003
3245 {
3246     // <Title>Boxing and unboxing</Title>
3247     // <Description>
3248     // Boxing to an object and unboxing from a dynamic
3249     // </Description>
3250     // <RelatedBugs></RelatedBugs>
3251     //<Expects Status=success></Expects>
3252     // <Code>
3253     public class MyClass
3254     {
3255         public int Field;
operator MyClass(int x)3256         public static explicit operator MyClass(int x)
3257         {
3258             return new MyClass()
3259             {
3260                 Field = x
3261             }
3262 
3263             ;
3264         }
3265 
operator int(MyClass x)3266         public static explicit operator int (MyClass x)
3267         {
3268             return x.Field;
3269         }
3270     }
3271 
3272     public class Test
3273     {
3274         [Fact]
DynamicCSharpRunTest()3275         public static void DynamicCSharpRunTest()
3276         {
3277             Assert.Equal(0, MainMethod(null));
3278         }
3279 
MainMethod(string[] args)3280         public static int MainMethod(string[] args)
3281         {
3282             dynamic d = (dynamic)(MyClass)(int)1;
3283             if ((int)d.Field != 1)
3284                 return 1;
3285             d = (object)(MyClass)1;
3286             if ((int)d.Field != 1)
3287                 return 1;
3288             return 0;
3289         }
3290     }
3291     // </Code>
3292 }
3293 
3294 
3295 
3296 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.explicit004.explicit004
3297 {
3298     public class Test
3299     {
3300         [Fact]
DynamicCSharpRunTest()3301         public static void DynamicCSharpRunTest()
3302         {
3303             Assert.Equal(0, MainMethod(null));
3304         }
3305 
MainMethod(string[] args)3306         public static int MainMethod(string[] args)
3307         {
3308             object d = (dynamic)(int)1;
3309             if ((int)d != 1)
3310                 return 1;
3311             return 0;
3312         }
3313     }
3314     // </Code>
3315 }
3316 
3317 
3318 
3319 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.implicit001.implicit001
3320 {
3321     public class Test
3322     {
3323         [Fact]
DynamicCSharpRunTest()3324         public static void DynamicCSharpRunTest()
3325         {
3326             Assert.Equal(0, MainMethod(null));
3327         }
3328 
MainMethod(string[] args)3329         public static int MainMethod(string[] args)
3330         {
3331             object o = "Foo";
3332             dynamic d = o;
3333             string s = (string)d;
3334             if (s != "Foo")
3335                 return 1;
3336             d = "Foo";
3337             o = d;
3338             s = (string)o;
3339             if (s != "Foo")
3340                 return 1;
3341             return 0;
3342         }
3343     }
3344     // </Code>
3345 }
3346 
3347 
3348 
3349 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.implicitarayinit001.implicitarayinit001
3350 {
3351     public class Test
3352     {
3353         [Fact]
DynamicCSharpRunTest()3354         public static void DynamicCSharpRunTest()
3355         {
3356             Assert.Equal(0, MainMethod(null));
3357         }
3358 
MainMethod(string[] args)3359         public static int MainMethod(string[] args)
3360         {
3361             dynamic dd = 23;
3362             var d = new[]
3363             {
3364             dd, dd, new object ()}
3365 
3366             ;
3367             if (d.Length == 3 && d[0] == 23 && d[1] == 23)
3368                 return 0;
3369             return 1;
3370         }
3371     }
3372     // </Code>
3373 }
3374 
3375 
3376 
3377 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.implicitarayinit002.implicitarayinit002
3378 {
3379     public class Test
3380     {
3381         [Fact]
DynamicCSharpRunTest()3382         public static void DynamicCSharpRunTest()
3383         {
3384             Assert.Equal(0, MainMethod(null));
3385         }
3386 
MainMethod(string[] args)3387         public static int MainMethod(string[] args)
3388         {
3389             dynamic dd = 23;
3390             var d = new[]
3391             {
3392             dd, dd
3393             }
3394 
3395             ;
3396             if (d.GetType() != typeof(dynamic[]))
3397                 return 1;
3398             return 0;
3399         }
3400     }
3401     // </Code>
3402 }
3403 
3404 
3405 
3406 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.implicitarayinit003.implicitarayinit003
3407 {
3408     public class Test
3409     {
3410         [Fact]
DynamicCSharpRunTest()3411         public static void DynamicCSharpRunTest()
3412         {
3413             Assert.Equal(0, MainMethod(null));
3414         }
3415 
MainMethod(string[] args)3416         public static int MainMethod(string[] args)
3417         {
3418             var d = new[]
3419             {
3420             (dynamic)2, (dynamic)"Foo"
3421             }
3422 
3423             ;
3424             if (d.GetType() != typeof(dynamic[]))
3425                 return 1;
3426             return 0;
3427         }
3428     }
3429     // </Code>
3430 }
3431 
3432 
3433 
3434 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.implicitarayinit004.implicitarayinit004
3435 {
3436     public class Test
3437     {
3438         [Fact]
DynamicCSharpRunTest()3439         public static void DynamicCSharpRunTest()
3440         {
3441             Assert.Equal(0, MainMethod(null));
3442         }
3443 
MainMethod(string[] args)3444         public static int MainMethod(string[] args)
3445         {
3446             var d = new[]
3447             {
3448             (dynamic)new
3449             {
3450             Name = "Foo"
3451             }
3452 
3453             , (dynamic)new
3454             {
3455             Address = "Bar"
3456             }
3457             }
3458 
3459             ;
3460             if (d.GetType() != typeof(dynamic[]))
3461                 return 1;
3462             return 0;
3463         }
3464     }
3465     // </Code>
3466 }
3467 
3468 
3469 
3470 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.initialize002.initialize002
3471 {
3472     public class Test
3473     {
3474         [Fact]
DynamicCSharpRunTest()3475         public static void DynamicCSharpRunTest()
3476         {
3477             Assert.Equal(0, MainMethod(null));
3478         }
3479 
MainMethod(string[] args)3480         public static int MainMethod(string[] args)
3481         {
3482             int x = int.MinValue;
3483             object o = (dynamic)x;
3484             dynamic d = 3;
3485             if ((int)o != x)
3486                 return 1;
3487             o = d;
3488             if ((int)o != 3)
3489                 return 1;
3490             d = new MyClass()
3491             {
3492                 Field = 3
3493             }
3494 
3495             ;
3496             o = d.Field;
3497             if ((int)o != 3)
3498                 return 1;
3499             d = new MyClass()
3500             {
3501                 Field = 3
3502             }
3503 
3504             ;
3505             o = d.GetNumber();
3506             if ((int)o != 3)
3507                 return 1;
3508             d = new MyClass()
3509             {
3510                 Field = 3
3511             }
3512 
3513             ;
3514             o = ((MyClass)d)[3];
3515             if ((int)o != 3)
3516                 return 1;
3517             return 0;
3518         }
3519 
3520         public class MyClass
3521         {
3522             public int Field;
GetNumber()3523             public int GetNumber()
3524             {
3525                 return Field;
3526             }
3527 
3528             public int this[int index]
3529             {
3530                 get
3531                 {
3532                     return Field;
3533                 }
3534             }
3535         }
3536     }
3537     // </Code>
3538 }
3539 
3540 
3541 
3542 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.initialize003.initialize003
3543 {
3544     public class Test
3545     {
3546         private static object s_foo = ((dynamic)new MyClass()
3547         {
3548             Field = 3
3549         }
3550 
3551         ).GetNumber();
3552 
3553         [Fact]
DynamicCSharpRunTest()3554         public static void DynamicCSharpRunTest()
3555         {
3556             Assert.Equal(0, MainMethod(null));
3557         }
3558 
MainMethod(string[] args)3559         public static int MainMethod(string[] args)
3560         {
3561             if ((int)s_foo != 3)
3562                 return 1;
3563             return 0;
3564         }
3565 
3566         public class MyClass
3567         {
3568             public int Field;
GetNumber()3569             public int GetNumber()
3570             {
3571                 return Field;
3572             }
3573 
3574             public int this[int index]
3575             {
3576                 get
3577                 {
3578                     return Field;
3579                 }
3580             }
3581         }
3582     }
3583     // </Code>
3584 }
3585 
3586 
3587 
3588 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.initialize004.initialize004
3589 {
3590     public class Test
3591     {
3592         private static object s_foo = ((dynamic)new MyClass()
3593         {
3594             Field = 3
3595         }
3596 
3597         ).Field;
3598         [Fact]
DynamicCSharpRunTest()3599         public static void DynamicCSharpRunTest()
3600         {
3601             Assert.Equal(0, MainMethod(null));
3602         }
3603 
MainMethod(string[] args)3604         public static int MainMethod(string[] args)
3605         {
3606             if ((int)s_foo != 3)
3607                 return 1;
3608             return 0;
3609         }
3610 
3611         public class MyClass
3612         {
3613             public int Field;
GetNumber()3614             public int GetNumber()
3615             {
3616                 return Field;
3617             }
3618 
3619             public int this[int index]
3620             {
3621                 get
3622                 {
3623                     return Field;
3624                 }
3625             }
3626         }
3627     }
3628     // </Code>
3629 }
3630 
3631 
3632 
3633 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.initialize005.initialize005
3634 {
3635     public class Test
3636     {
3637         private static object s_foo = ((MyClass)((dynamic)new MyClass()
3638         {
3639             Field = 3
3640         }
3641 
3642         ))[3];
3643         [Fact]
DynamicCSharpRunTest()3644         public static void DynamicCSharpRunTest()
3645         {
3646             Assert.Equal(0, MainMethod(null));
3647         }
3648 
MainMethod(string[] args)3649         public static int MainMethod(string[] args)
3650         {
3651             if ((int)s_foo != 3)
3652                 return 1;
3653             return 0;
3654         }
3655 
3656         public class MyClass
3657         {
3658             public int Field;
GetNumber()3659             public int GetNumber()
3660             {
3661                 return Field;
3662             }
3663 
3664             public int this[int index]
3665             {
3666                 get
3667                 {
3668                     return Field;
3669                 }
3670             }
3671         }
3672     }
3673     // </Code>
3674 }
3675 
3676 
3677 
3678 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.initialize006.initialize006
3679 {
3680     public class Test
3681     {
3682         private static dynamic s_foo = (new MyClass()
3683         {
3684             Field = 3
3685         }
3686 
3687         );
3688         [Fact]
DynamicCSharpRunTest()3689         public static void DynamicCSharpRunTest()
3690         {
3691             Assert.Equal(0, MainMethod(null));
3692         }
3693 
MainMethod(string[] args)3694         public static int MainMethod(string[] args)
3695         {
3696             if ((int)s_foo.Field != 3)
3697                 return 1;
3698             return 0;
3699         }
3700 
3701         public class MyClass
3702         {
3703             public int Field;
GetNumber()3704             public int GetNumber()
3705             {
3706                 return Field;
3707             }
3708 
3709             public int this[int index]
3710             {
3711                 get
3712                 {
3713                     return Field;
3714                 }
3715             }
3716         }
3717     }
3718     // </Code>
3719 }
3720 
3721 
3722 
3723 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.initialize007.initialize007
3724 {
3725     public class Test
3726     {
3727         [Fact]
DynamicCSharpRunTest()3728         public static void DynamicCSharpRunTest()
3729         {
3730             Assert.Equal(0, MainMethod(null));
3731         }
3732 
MainMethod(string[] args)3733         public static int MainMethod(string[] args)
3734         {
3735             dynamic o = new object();
3736             return 0;
3737         }
3738     }
3739     // </Code>
3740 }
3741 
3742 
3743 
3744 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.lambda002.lambda002
3745 {
3746     // <Title>Lambda expressions</Title>
3747     // <Description>match build-in delegates
3748     // </Description>
3749     // <RelatedBugs></RelatedBugs>
3750     //<Expects Status=success></Expects>
3751     // <Code>
3752     using System;
3753 
3754     public class Test
3755     {
3756         [Fact]
DynamicCSharpRunTest()3757         public static void DynamicCSharpRunTest()
3758         {
3759             Assert.Equal(0, MainMethod(null));
3760         }
3761 
MainMethod(string[] args)3762         public static int MainMethod(string[] args)
3763         {
3764             int state = 0;
3765             Action<dynamic, dynamic> lambda1 = (dynamic x, dynamic y) =>
3766             {
3767                 state = x % y;
3768             }
3769 
3770             ;
3771             lambda1(7, 2);
3772             bool ret = 1 == state;
3773             dynamic d = "A";
3774             Func<object, dynamic, string> lambda2 = (x, y) => d + x + y;
3775             ret &= "ABC" == lambda2("B", "C");
3776             return ret ? 0 : 1;
3777         }
3778     }
3779     // </Code>
3780 }
3781 
3782 
3783 
3784 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.lambda003.lambda003
3785 {
3786     // <Title>Lambda expressions</Title>
3787     // <Description>lambda as method parameter
3788     // </Description>
3789     // <RelatedBugs></RelatedBugs>
3790     //<Expects Status=success></Expects>
3791     // <Code>
3792 
3793     public class Test
3794     {
3795         [Fact]
DynamicCSharpRunTest()3796         public static void DynamicCSharpRunTest()
3797         {
3798             Assert.Equal(0, MainMethod());
3799         }
3800 
MainMethod()3801         public static int MainMethod()
3802         {
3803             dynamic dVal = "L";
3804             bool ret = "L::L" == Lambda0(dVal)();
3805             dVal = (byte)9;
3806             ret &= 81 == Lambda1((D1)(x => (short)(dVal * x)), dVal);
3807             dVal = 'q';
3808             ret &= 'q' == Lambda2(dVal)(true, 'c');
3809             return ret ? 0 : 1;
3810         }
3811 
Lambda0(dynamic dVal)3812         public static D0 Lambda0(dynamic dVal)
3813         {
3814             return () => dVal + "::" + dVal;
3815         }
3816 
Lambda1(D1 dd, dynamic dVal)3817         public static short Lambda1(D1 dd, dynamic dVal)
3818         {
3819             return dd(dVal);
3820         }
3821 
Lambda2(dynamic dVal)3822         public static D2 Lambda2(dynamic dVal)
3823         {
3824             return (x, y) =>
3825             {
3826                 if (x)
3827                     return (char)dVal;
3828                 else
3829                     return y;
3830             }
3831 
3832             ;
3833         }
3834 
D0()3835         public delegate string D0();
D1(byte p)3836         public delegate short D1(byte p);
D2(bool p1, char p2)3837         public delegate char D2(bool p1, char p2);
3838     }
3839     // </Code>
3840 }
3841 
3842 
3843 
3844 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.lambda004b.lambda004b
3845 {
3846     // <Title>Lambda expressions</Title>
3847     // <Description>Overload
3848     // </Description>
3849     // <RelatedBugs></RelatedBugs>
3850     //<Expects Status=success></Expects>
3851     // <Code>
3852     using System;
3853     using System.Linq.Expressions;
3854 
D(long x, object y)3855     public delegate dynamic D(long x, object y);
3856     public class Test
3857     {
3858         [Fact]
DynamicCSharpRunTest()3859         public static void DynamicCSharpRunTest()
3860         {
3861             Assert.Equal(0, MainMethod(null));
3862         }
3863 
MainMethod(string[] args)3864         public static int MainMethod(string[] args)
3865         {
3866             long d1 = -1;
3867             var d2 = new Test();
3868             bool ret = d2.RunTest(d1, d2);
3869             return ret ? 0 : 1;
3870         }
3871 
M(D e)3872         private int M(D e)
3873         {
3874             return 11;
3875         }
3876 
M(Action<long, object, dynamic> f)3877         private int M(Action<long, object, dynamic> f)
3878         {
3879             return 22;
3880         }
3881 
M(Func<string, object, dynamic> f)3882         private int M(Func<string, object, dynamic> f)
3883         {
3884             return 33;
3885         }
3886 
M1(Expression<D> e)3887         private int M1(Expression<D> e)
3888         {
3889             return 44;
3890         }
3891 
M1(Expression<Func<string, object, dynamic>> e)3892         private int M1(Expression<Func<string, object, dynamic>> e)
3893         {
3894             return 66;
3895         }
3896 
RunTest(dynamic d1, dynamic d2)3897         private bool RunTest(dynamic d1, dynamic d2)
3898         {
3899             bool ret = 11 == M((p1, p2) => p1 * 100);
3900             ret &= 22 == M((p1, p2, p3) =>
3901             {
3902             }
3903 
3904             );
3905             ret &= 33 == M((string p1, dynamic p2) => p1 + p2.ToString());
3906             ret &= 44 == M1((long p1, dynamic p2) => p1 * 100);
3907             ret &= 66 == M1((string p1, dynamic p2) => p1);
3908             return ret;
3909         }
3910     }
3911     // </Code>
3912 }
3913 
3914 
3915 
3916 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.lambda005.lambda005
3917 {
3918     // <Title>Lambda expressions</Title>
3919     // <Description>unsafe
3920     // </Description>
3921     // <RelatedBugs></RelatedBugs>
3922     //<Expects Status=success></Expects>
3923     // <Code>
3924     //unsafe delegate byte D(byte* p1, dynamic p2);
3925     //[TestClass]public unsafe class Test
3926     //{
3927     //static int M(D e) { return 1; }
3928     //static int M(Func<dynamic, object, dynamic> f) { return 0; }
3929     //static int M1(Expression<D> e) { return 1; }
3930     //static int M1(Func<byte, dynamic, object> f) { return 0; }
3931     //[Test][Priority(Priority.Priority2)]public void DynamicCSharpRunTest(){Assert.AreEqual(0, MainMethod(null));} public static int MainMethod(string[] args)
3932     //{
3933     //bool ret = 0 == M((i, j) => i);
3934     //ret &= 1 == M((i, j) => *i);
3935     //ret &= 0 == M1((x, y) => 2 * x);
3936     //System.Console.WriteLine(ret);
3937     //return ret ? 0 : 1;
3938     //}
3939     //}
3940     // </Code>
3941 }
3942 
3943 
3944 
3945 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.lambda006.lambda006
3946 {
3947     // <Title>Lambda expressions</Title>
3948     // <Description>
3949     // </Description>
3950     // <RelatedBugs></RelatedBugs>
3951     //<Expects Status=success></Expects>
3952     // <Code>
3953     using System;
3954     using System.Linq.Expressions;
3955 
3956     public class Test
3957     {
3958 
DynamicCSharpRunTest()3959         public static void DynamicCSharpRunTest()
3960         {
3961             Assert.Equal(0, MainMethod(null));
3962         }
3963 
MainMethod(string[] args)3964         public static int MainMethod(string[] args)
3965         {
3966             bool ret = true;
3967             dynamic d = 3;
3968             Expression<Func<int, object>> del = x => d;
3969             dynamic xx = del.Compile()(d);
3970             try
3971             {
3972                 xx.Foo();
3973                 ret = false;
3974             }
3975             catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
3976             {
3977                 if (!ErrorVerifier.Verify(ErrorMessageId.NoSuchMember, e.Message, "int", "Foo"))
3978                     ret = false;
3979             }
3980 
3981             Expression<Func<dynamic, object>> del1 = x => d;
3982             dynamic y = del.Compile()(d);
3983             try
3984             {
3985                 y.Foo();
3986                 ret = false;
3987             }
3988             catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
3989             {
3990                 if (!ErrorVerifier.Verify(ErrorMessageId.NoSuchMember, e.Message, "int", "Foo"))
3991                     ret = false;
3992             }
3993 
3994             Expression<Func<object, dynamic>> del2 = x => x;
3995             dynamic z = del.Compile()(3);
3996             try
3997             {
3998                 z.Foo();
3999                 ret = false;
4000             }
4001             catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
4002             {
4003                 if (!ErrorVerifier.Verify(ErrorMessageId.NoSuchMember, e.Message, "int", "Foo"))
4004                     ret = false;
4005             }
4006 
4007             return ret ? 0 : 1;
4008         }
4009     }
4010     // </Code>
4011 }
4012 
4013 
4014 
4015 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.lambda007.lambda007
4016 {
4017     // <Title>Lambda expressions</Title>
4018     // <Description>with anonymous method
4019     // </Description>
4020     // <RelatedBugs></RelatedBugs>
4021     //<Expects Status=success></Expects>
4022     // <Code>
4023 
D(object p1, char p2)4024     public delegate dynamic D(object p1, char p2);
4025     public class Test
4026     {
4027         [Fact]
DynamicCSharpRunTest()4028         public static void DynamicCSharpRunTest()
4029         {
4030             Assert.Equal(0, MainMethod());
4031         }
4032 
MainMethod()4033         public static int MainMethod()
4034         {
4035             D lambda = (x, y) =>
4036             {
4037                 D d = delegate (dynamic i, char j)
4038                 {
4039                     return j;
4040                 }
4041 
4042                 ;
4043                 return d;
4044             }
4045 
4046             ;
4047             bool ret = 'q' == lambda(null, 'p')(null, 'q');
4048             //
4049             lambda = (x, y) =>
4050             {
4051                 D d = delegate
4052                 {
4053                     return y;
4054                 }
4055 
4056                 ;
4057                 return d;
4058             }
4059 
4060             ;
4061             ret &= 'p' == lambda(null, 'p')(null, 'q');
4062             return ret ? 0 : 1;
4063         }
4064     }
4065     // </Code>
4066 }
4067 
4068 
4069 
4070 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.lambda008.lambda008
4071 {
4072     // <Title>Lambda expressions</Title>
4073     // <Description>context
4074     // </Description>
4075     // <RelatedBugs></RelatedBugs>
4076     //<Expects Status=success></Expects>
4077     // <Code>
4078     //<Expects Status=warning>\(32,78\).*CS0162</Expects>
4079     using System;
4080     using System.Linq.Expressions;
4081 
4082     public class LMD : IDisposable
4083     {
LMD(Func<object, dynamic> p)4084         public LMD(Func<object, dynamic> p)
4085         {
4086         }
4087 
Dispose()4088         public void Dispose()
4089         {
4090         }
4091     }
4092 
4093     public class Test
4094     {
4095         private static int s_status = 0;
4096         [Fact]
DynamicCSharpRunTest()4097         public static void DynamicCSharpRunTest()
4098         {
4099             Assert.Equal(0, MainMethod());
4100         }
4101 
MainMethod()4102         public static int MainMethod()
4103         {
4104             Expression<Func<object, dynamic>> del = x => x;
4105             dynamic d = del.Compile()(12345678);
4106             lock (d)
4107             {
4108                 using (var obj = new LMD(y => y))
4109                 {
4110                     var v = checked(d);
4111                     var arr = new[]
4112                     {
4113                     new LMD(x => x), new LMD(y => y), new LMD(z => z)}
4114 
4115                     ;
4116                     foreach (dynamic i in arr)
4117                     {
4118                         s_status++;
4119                     }
4120 
4121                     for (dynamic i = d; ((Func<object, dynamic>)(y => true))(d); new LMD(z => z))
4122                     {
4123                         ++s_status;
4124                         break;
4125                     }
4126                 }
4127             }
4128 
4129             return s_status == 4 ? 0 : 1;
4130         }
4131     }
4132     // </Code>
4133 }
4134 
4135 
4136 
4137 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.lambda009.lambda009
4138 {
4139     // <Title>Lambda expressions</Title>
4140     // <Description>
4141     // </Description>
4142     // <RelatedBugs></RelatedBugs>
4143     //<Expects Status=success></Expects>
4144     // <Code>
4145     using System;
4146 
4147     public class Test
4148     {
4149         [Fact]
DynamicCSharpRunTest()4150         public static void DynamicCSharpRunTest()
4151         {
4152             Assert.Equal(0, MainMethod(null));
4153         }
4154 
MainMethod(string[] args)4155         public static int MainMethod(string[] args)
4156         {
4157             Func<dynamic, object> del = x => x;
4158             var Xx = del(3);
4159             if ((int)Xx != 3)
4160                 return 1;
4161             return 0;
4162         }
4163     }
4164     // </Code>
4165 }
4166 
4167 
4168 
4169 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.lambda010.lambda010
4170 {
4171     // <Title>Lambda expressions</Title>
4172     // <Description>
4173     // </Description>
4174     // <RelatedBugs></RelatedBugs>
4175     //<Expects Status=success></Expects>
4176     // <Code>
4177     using System;
4178 
4179     public class Test
4180     {
4181         [Fact]
DynamicCSharpRunTest()4182         public static void DynamicCSharpRunTest()
4183         {
4184             Assert.Equal(0, MainMethod(null));
4185         }
4186 
MainMethod(string[] args)4187         public static int MainMethod(string[] args)
4188         {
4189             Func<object, dynamic> del = x => x;
4190             var Xx = del(3);
4191             if ((int)Xx != 3)
4192                 return 1;
4193             try
4194             {
4195                 Xx.Foo();
4196             }
4197             catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
4198             {
4199                 if (ErrorVerifier.Verify(ErrorMessageId.NoSuchMember, e.Message, "int", "Foo"))
4200                     return 0;
4201             }
4202 
4203             return 1;
4204         }
4205     }
4206     // </Code>
4207 }
4208 
4209 
4210 
4211 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.lambda011.lambda011
4212 {
4213     // <Title>Lambda expressions</Title>
4214     // <Description>
4215     // </Description>
4216     // <RelatedBugs></RelatedBugs>
4217     //<Expects Status=success></Expects>
4218     // <Code>
4219     using System;
4220 
4221     public class Test
4222     {
4223         [Fact]
DynamicCSharpRunTest()4224         public static void DynamicCSharpRunTest()
4225         {
4226             Assert.Equal(0, MainMethod(null));
4227         }
4228 
MainMethod(string[] args)4229         public static int MainMethod(string[] args)
4230         {
4231             Func<dynamic, dynamic> del = x => x;
4232             var Xx = del(3);
4233             if ((int)Xx != 3)
4234                 return 1;
4235             try
4236             {
4237                 Xx.Foo();
4238             }
4239             catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
4240             {
4241                 if (ErrorVerifier.Verify(ErrorMessageId.NoSuchMember, e.Message, "int", "Foo"))
4242                     return 0;
4243             }
4244 
4245             return 1;
4246         }
4247     }
4248     // </Code>
4249 }
4250 
4251 
4252 
4253 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.lambda012.lambda012
4254 {
4255     // <Title>Lambda expressions</Title>
4256     // <Description>
4257     // </Description>
4258     // <RelatedBugs></RelatedBugs>
4259     //<Expects Status=success></Expects>
4260     // <Code>
4261     using System;
4262 
4263     public class myClass
4264     {
4265         public int Foo
4266         {
4267             get
4268             {
4269                 return 0;
4270             }
4271         }
4272     }
4273 
4274     public class Test
4275     {
4276         [Fact]
DynamicCSharpRunTest()4277         public static void DynamicCSharpRunTest()
4278         {
4279             Assert.Equal(0, MainMethod(null));
4280         }
4281 
MainMethod(string[] args)4282         public static int MainMethod(string[] args)
4283         {
4284             dynamic d = new myClass();
4285             Func<int, int> del = x => d.Foo;
4286             return del(3);
4287         }
4288     }
4289     // </Code>
4290 }
4291 
4292 
4293 
4294 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.lambda013.lambda013
4295 {
4296     // <Title>Lambda expressions</Title>
4297     // <Description>
4298     // </Description>
4299     // <RelatedBugs></RelatedBugs>
4300     //<Expects Status=success></Expects>
4301     // <Code>
4302     using System;
4303 
4304     public class myClass
4305     {
Foo()4306         public int Foo()
4307         {
4308             return 0;
4309         }
4310     }
4311 
4312     public class Test
4313     {
4314         [Fact]
DynamicCSharpRunTest()4315         public static void DynamicCSharpRunTest()
4316         {
4317             Assert.Equal(0, MainMethod(null));
4318         }
4319 
MainMethod(string[] args)4320         public static int MainMethod(string[] args)
4321         {
4322             dynamic d = new myClass();
4323             Func<int, int> del = x => d.Foo();
4324             return del(32);
4325         }
4326     }
4327     // </Code>
4328 }
4329 
4330 
4331 
4332 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.lambda014.lambda014
4333 {
4334     // <Title>Lambda expressions</Title>
4335     // <Description>
4336     // </Description>
4337     // <RelatedBugs></RelatedBugs>
4338     //<Expects Status=success></Expects>
4339     // <Code>
4340     using System;
4341 
4342     public class myClass
4343     {
Foo()4344         public int Foo()
4345         {
4346             return 0;
4347         }
4348     }
4349 
4350     public class Test
4351     {
4352         [Fact]
DynamicCSharpRunTest()4353         public static void DynamicCSharpRunTest()
4354         {
4355             Assert.Equal(0, MainMethod(null));
4356         }
4357 
MainMethod(string[] args)4358         public static int MainMethod(string[] args)
4359         {
4360             dynamic d = 3;
4361             Func<int, int> del = x => d;
4362             if (del(10) == 3)
4363                 return 0;
4364             return 1;
4365         }
4366     }
4367     // </Code>
4368 }
4369 
4370 
4371 
4372 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.lambda015.lambda015
4373 {
4374     // <Title>Lambda expressions</Title>
4375     // <Description>
4376     // </Description>
4377     // <RelatedBugs></RelatedBugs>
4378     //<Expects Status=success></Expects>
4379     // <Code>
4380     using System;
4381 
4382     public class Test
4383     {
4384         [Fact]
DynamicCSharpRunTest()4385         public static void DynamicCSharpRunTest()
4386         {
4387             Assert.Equal(0, MainMethod(null));
4388         }
4389 
MainMethod(string[] args)4390         public static int MainMethod(string[] args)
4391         {
4392             dynamic d = 3;
4393             Func<int, int> del = x => d;
4394             long result = del(10);
4395             if (result == 3)
4396                 return 0;
4397             return 1;
4398         }
4399     }
4400     // </Code>
4401 }
4402 
4403 
4404 
4405 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.lambda016.lambda016
4406 {
4407     // <Title>Lambda expressions</Title>
4408     // <Description>
4409     // </Description>
4410     // <RelatedBugs></RelatedBugs>
4411     //<Expects Status=success></Expects>
4412     // <Code>
4413     using System;
4414 
4415     public class Test
4416     {
4417         [Fact]
DynamicCSharpRunTest()4418         public static void DynamicCSharpRunTest()
4419         {
4420             Assert.Equal(0, MainMethod(null));
4421         }
4422 
MainMethod(string[] args)4423         public static int MainMethod(string[] args)
4424         {
4425             Func<int, dynamic> del = x => x + 1;
4426             int result = del(3);
4427             if (result == 4)
4428                 return 0;
4429             return 1;
4430         }
4431     }
4432     // </Code>
4433 }
4434 
4435 
4436 
4437 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.lambda017.lambda017
4438 {
4439     // <Title>Lambda expressions</Title>
4440     // <Description>
4441     // </Description>
4442     // <RelatedBugs></RelatedBugs>
4443     //<Expects Status=success></Expects>
4444     // <Code>
4445     using System;
4446 
4447     public class Test
4448     {
4449         public class Base
4450         {
4451             public int Field;
4452         }
4453 
4454         public class Derived : Base
4455         {
4456         }
4457 
4458         [Fact]
DynamicCSharpRunTest()4459         public static void DynamicCSharpRunTest()
4460         {
4461             Assert.Equal(0, MainMethod(null));
4462         }
4463 
MainMethod(string[] args)4464         public static int MainMethod(string[] args)
4465         {
4466             Func<int, dynamic> del = x => new Derived()
4467             {
4468                 Field = x
4469             }
4470 
4471             ;
4472             dynamic d = 3;
4473             Base result = del(d);
4474             if (result.Field == 3)
4475                 return 0;
4476             return 1;
4477         }
4478     }
4479     // </Code>
4480 }
4481 
4482 
4483 
4484 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.lambda018.lambda018
4485 {
4486     // <Title>Lambda expressions</Title>
4487     // <Description>
4488     // </Description>
4489     // <RelatedBugs></RelatedBugs>
4490     //<Expects Status=success></Expects>
4491     // <Code>
4492     using System;
4493 
4494     public class Test
4495     {
4496         public class Base
4497         {
4498             public int Field;
4499         }
4500 
4501         public class Derived : Base
4502         {
4503         }
4504 
4505         [Fact]
DynamicCSharpRunTest()4506         public static void DynamicCSharpRunTest()
4507         {
4508             Assert.Equal(0, MainMethod(null));
4509         }
4510 
MainMethod(string[] args)4511         public static int MainMethod(string[] args)
4512         {
4513             Func<int, dynamic> del = x => new Base()
4514             {
4515                 Field = x
4516             }
4517 
4518             ;
4519             dynamic d = 3;
4520             try
4521             {
4522                 Derived result = del(d);
4523             }
4524             catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
4525             {
4526                 if (ErrorVerifier.Verify(ErrorMessageId.NoImplicitConvCast, e.Message, "Test.Base", "Test.Derived"))
4527                     return 0;
4528             }
4529 
4530             return 1;
4531         }
4532     }
4533     // </Code>
4534 }
4535 
4536 
4537 
4538 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.lambda019.lambda019
4539 {
4540     // <Title>Lambda expressions</Title>
4541     // <Description>
4542     // </Description>
4543     // <RelatedBugs></RelatedBugs>
4544     //<Expects Status=success></Expects>
4545     // <Code>
4546     using System;
4547 
4548     public class Test
4549     {
4550         public class Class1
4551         {
4552             public int Field;
4553         }
4554 
4555         public class Class2
4556         {
4557             public int Field;
operator Class2(Class1 p1)4558             public static implicit operator Class2(Class1 p1)
4559             {
4560                 return new Class2()
4561                 {
4562                     Field = p1.Field + 1
4563                 }
4564 
4565                 ;
4566             }
4567         }
4568 
4569         [Fact]
DynamicCSharpRunTest()4570         public static void DynamicCSharpRunTest()
4571         {
4572             Assert.Equal(0, MainMethod(null));
4573         }
4574 
MainMethod(string[] args)4575         public static int MainMethod(string[] args)
4576         {
4577             Func<int, dynamic> del = x => new Class1()
4578             {
4579                 Field = x
4580             }
4581 
4582             ;
4583             dynamic d = 3;
4584             Class2 result = del(d);
4585             if (result.Field == 4)
4586                 return 0;
4587             return 1;
4588         }
4589     }
4590     // </Code>
4591 }
4592 
4593 
4594 
4595 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.lambda020.lambda020
4596 {
4597     // <Title>Lambda expressions</Title>
4598     // <Description>
4599     // </Description>
4600     // <RelatedBugs></RelatedBugs>
4601     //<Expects Status=success></Expects>
4602     // <Code>
4603     using System;
4604 
4605     public class Test
4606     {
4607         public class Class1
4608         {
4609             public int Field;
4610         }
4611 
4612         public class Class2
4613         {
4614             public int Field;
operator Class2(Class1 p1)4615             public static explicit operator Class2(Class1 p1)
4616             {
4617                 return new Class2()
4618                 {
4619                     Field = p1.Field + 1
4620                 }
4621 
4622                 ;
4623             }
4624         }
4625 
4626         [Fact]
DynamicCSharpRunTest()4627         public static void DynamicCSharpRunTest()
4628         {
4629             Assert.Equal(0, MainMethod(null));
4630         }
4631 
MainMethod(string[] args)4632         public static int MainMethod(string[] args)
4633         {
4634             Func<int, dynamic> del = x => new Class1()
4635             {
4636                 Field = x
4637             }
4638 
4639             ;
4640             dynamic d = 3;
4641             Class2 result = (Class2)del(d); // call explicit conversion.
4642             if (result.Field == 4)
4643                 return 0;
4644             return 1;
4645         }
4646     }
4647     // </Code>
4648 }
4649 
4650 
4651 
4652 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.memberinitofanontype001.memberinitofanontype001
4653 {
4654     public class Test
4655     {
4656         [Fact]
DynamicCSharpRunTest()4657         public static void DynamicCSharpRunTest()
4658         {
4659             Assert.Equal(0, MainMethod(null));
4660         }
4661 
MainMethod(string[] args)4662         public static int MainMethod(string[] args)
4663         {
4664             dynamic myInt = 3;
4665             dynamic myString = "foo";
4666             dynamic myNullArr = new int?[]
4667             {
4668             1, null
4669             }
4670 
4671             ;
4672             dynamic myArr = new decimal[]
4673             {
4674             decimal.MaxValue, decimal.One
4675             }
4676 
4677             ;
4678             dynamic myDec = decimal.MaxValue;
4679             var mc = new
4680             {
4681                 Field = myInt,
4682                 Prop = myString,
4683                 NullArray = myNullArr,
4684                 Array = myArr,
4685                 Obj = myInt
4686             }
4687 
4688             ;
4689             if ((int)mc.Field != 3)
4690                 return 1;
4691             if ((string)mc.Prop != "foo")
4692                 return 1;
4693             if (((int?[])mc.NullArray).Length != 2 || ((int?[])mc.NullArray)[1] != null)
4694                 return 1;
4695             if (((decimal[])mc.Array).Length != 2 || ((decimal[])mc.Array)[0] != decimal.MaxValue)
4696                 return 1;
4697             if ((int)mc.Obj != 3)
4698                 return 1;
4699             return 0;
4700         }
4701     }
4702     // </Code>
4703 }
4704 
4705 
4706 
4707 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.memberinitofanontype002.memberinitofanontype002
4708 {
4709     public class Test
4710     {
4711         [Fact]
DynamicCSharpRunTest()4712         public static void DynamicCSharpRunTest()
4713         {
4714             Assert.Equal(0, MainMethod(null));
4715         }
4716 
MainMethod(string[] args)4717         public static int MainMethod(string[] args)
4718         {
4719             dynamic myInt = 3;
4720             dynamic myString = "foo";
4721             dynamic myNullArr = new int?[]
4722             {
4723             1, null
4724             }
4725 
4726             ;
4727             dynamic myArr = new decimal[]
4728             {
4729             decimal.MaxValue, decimal.One
4730             }
4731 
4732             ;
4733             dynamic myDec = decimal.MaxValue;
4734             var mc = new
4735             {
4736                 Field = (int)myInt,
4737                 Prop = (string)myString,
4738                 NullArray = (int?[])myNullArr,
4739                 Array = (decimal[])myArr,
4740                 Obj = myInt
4741             }
4742 
4743             ;
4744             if (mc.Field != 3)
4745                 return 1;
4746             if (mc.Prop != "foo")
4747                 return 1;
4748             if (mc.NullArray.Length != 2 || mc.NullArray[1] != null)
4749                 return 1;
4750             if (mc.Array.Length != 2 || mc.Array[0] != decimal.MaxValue)
4751                 return 1;
4752             if ((int)mc.Obj != 3)
4753                 return 1;
4754             return 0;
4755         }
4756     }
4757     // </Code>
4758 }
4759 
4760 
4761 
4762 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.memberinitofobjinit001.memberinitofobjinit001
4763 {
4764     // <Title>Member initializer of object initializer</Title>
4765     // <Description>
4766     // </Description>
4767     // <RelatedBugs></RelatedBugs>
4768     //<Expects Status=success></Expects>
4769     // <Code>
4770     public class MyClass
4771     {
4772         private string _p = string.Empty;
4773         private decimal[] _arr;
4774         public int Field;
4775         public string Prop
4776         {
4777             get
4778             {
4779                 return _p;
4780             }
4781 
4782             set
4783             {
4784                 _p = value;
4785             }
4786         }
4787 
4788         public int?[] NullArray;
4789         public decimal[] Array
4790         {
4791             get
4792             {
4793                 return _arr;
4794             }
4795 
4796             set
4797             {
4798                 _arr = value;
4799             }
4800         }
4801 
4802         public object Obj;
4803     }
4804 
4805     public class Test
4806     {
4807         [Fact]
DynamicCSharpRunTest()4808         public static void DynamicCSharpRunTest()
4809         {
4810             Assert.Equal(0, MainMethod(null));
4811         }
4812 
MainMethod(string[] args)4813         public static int MainMethod(string[] args)
4814         {
4815             dynamic myInt = 3;
4816             dynamic myString = "foo";
4817             dynamic myNullArr = new int?[]
4818             {
4819             1, null
4820             }
4821 
4822             ;
4823             dynamic myArr = new decimal[]
4824             {
4825             decimal.MaxValue, decimal.One
4826             }
4827 
4828             ;
4829             dynamic myDec = decimal.MaxValue;
4830             MyClass mc = new MyClass()
4831             {
4832                 Field = myInt,
4833                 Prop = myString,
4834                 NullArray = myNullArr,
4835                 Array = myArr,
4836                 Obj = myInt
4837             }
4838 
4839             ;
4840             if (mc.Field != 3)
4841                 return 1;
4842             if (mc.Prop != "foo")
4843                 return 1;
4844             if (mc.NullArray.Length != 2 || mc.NullArray[1] != null)
4845                 return 1;
4846             if (mc.Array.Length != 2 || mc.Array[0] != decimal.MaxValue)
4847                 return 1;
4848             if ((int)mc.Obj != 3)
4849                 return 1;
4850             return 0;
4851         }
4852     }
4853     // </Code>
4854 }
4855 
4856 
4857 
4858 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.memberinitofobjinit002.memberinitofobjinit002
4859 {
4860     // <Title>Member initializer of object initializer</Title>
4861     // <Description>
4862     // </Description>
4863     // <RelatedBugs></RelatedBugs>
4864     //<Expects Status=success></Expects>
4865     // <Code>
4866     public class MyClass
4867     {
4868         private object _p = string.Empty;
4869         private object _arr;
4870         public object Field;
4871         public object Prop
4872         {
4873             get
4874             {
4875                 return _p;
4876             }
4877 
4878             set
4879             {
4880                 _p = value;
4881             }
4882         }
4883 
4884         public object NullArray;
4885         public object Array
4886         {
4887             get
4888             {
4889                 return _arr;
4890             }
4891 
4892             set
4893             {
4894                 _arr = value;
4895             }
4896         }
4897 
4898         public object Obj;
4899     }
4900 
4901     public class Test
4902     {
4903         [Fact]
DynamicCSharpRunTest()4904         public static void DynamicCSharpRunTest()
4905         {
4906             Assert.Equal(0, MainMethod(null));
4907         }
4908 
MainMethod(string[] args)4909         public static int MainMethod(string[] args)
4910         {
4911             dynamic myInt = 3;
4912             dynamic myString = "foo";
4913             dynamic myNullArr = new int?[]
4914             {
4915             1, null
4916             }
4917 
4918             ;
4919             dynamic myArr = new decimal[]
4920             {
4921             decimal.MaxValue, decimal.One
4922             }
4923 
4924             ;
4925             dynamic myDec = decimal.MaxValue;
4926             MyClass mc = new MyClass()
4927             {
4928                 Field = myInt,
4929                 Prop = myString,
4930                 NullArray = myNullArr,
4931                 Array = myArr,
4932                 Obj = myInt
4933             }
4934 
4935             ;
4936             if ((int)mc.Field != 3)
4937                 return 1;
4938             if ((string)mc.Prop != "foo")
4939                 return 1;
4940             if (((int?[])mc.NullArray).Length != 2 || ((int?[])mc.NullArray)[1] != null)
4941                 return 1;
4942             if (((decimal[])mc.Array).Length != 2 || ((decimal[])mc.Array)[0] != decimal.MaxValue)
4943                 return 1;
4944             if ((int)mc.Obj != 3)
4945                 return 1;
4946             return 0;
4947         }
4948     }
4949     // </Code>
4950 }
4951 
4952 
4953 
4954 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.memberinitofobjinit003.memberinitofobjinit003
4955 {
4956     // <Title>Member initializer of object initializer</Title>
4957     // <Description>
4958     // </Description>
4959     // <RelatedBugs></RelatedBugs>
4960     //<Expects Status=success></Expects>
4961     // <Code>
4962     public class MyClass
4963     {
4964         private object _p = string.Empty;
4965         private object _arr;
4966         public dynamic Field;
4967         public dynamic Prop
4968         {
4969             get
4970             {
4971                 return _p;
4972             }
4973 
4974             set
4975             {
4976                 _p = value;
4977             }
4978         }
4979 
4980         public dynamic NullArray;
4981         public dynamic Array
4982         {
4983             get
4984             {
4985                 return _arr;
4986             }
4987 
4988             set
4989             {
4990                 _arr = value;
4991             }
4992         }
4993 
4994         public dynamic Obj;
4995     }
4996 
4997     public class Test
4998     {
4999         [Fact]
DynamicCSharpRunTest()5000         public static void DynamicCSharpRunTest()
5001         {
5002             Assert.Equal(0, MainMethod(null));
5003         }
5004 
MainMethod(string[] args)5005         public static int MainMethod(string[] args)
5006         {
5007             object myInt = 3;
5008             object myString = "foo";
5009             object myNullArr = new int?[]
5010             {
5011             1, null
5012             }
5013 
5014             ;
5015             object myArr = new decimal[]
5016             {
5017             decimal.MaxValue, decimal.One
5018             }
5019 
5020             ;
5021             object myDec = decimal.MaxValue;
5022             MyClass mc = new MyClass()
5023             {
5024                 Field = myInt,
5025                 Prop = myString,
5026                 NullArray = myNullArr,
5027                 Array = myArr,
5028                 Obj = myInt
5029             }
5030 
5031             ;
5032             if ((int)mc.Field != 3)
5033                 return 1;
5034             if ((string)mc.Prop != "foo")
5035                 return 1;
5036             if (((int?[])mc.NullArray).Length != 2 || ((int?[])mc.NullArray)[1] != null)
5037                 return 1;
5038             if (((decimal[])mc.Array).Length != 2 || ((decimal[])mc.Array)[0] != decimal.MaxValue)
5039                 return 1;
5040             if ((int)mc.Obj != 3)
5041                 return 1;
5042             return 0;
5043         }
5044     }
5045     // </Code>
5046 }
5047 
5048 
5049 
5050 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.memberinitofobjinit004.memberinitofobjinit004
5051 {
5052     // <Title>Member initializer of object initializer</Title>
5053     // <Description>
5054     // </Description>
5055     // <RelatedBugs></RelatedBugs>
5056     //<Expects Status=success></Expects>
5057     // <Code>
5058     public class MyClass
5059     {
5060         private object _p = string.Empty;
5061         private object _arr;
5062         public dynamic Field;
5063         public dynamic Prop
5064         {
5065             get
5066             {
5067                 return _p;
5068             }
5069 
5070             set
5071             {
5072                 _p = value;
5073             }
5074         }
5075 
5076         public dynamic NullArray;
5077         public dynamic Array
5078         {
5079             get
5080             {
5081                 return _arr;
5082             }
5083 
5084             set
5085             {
5086                 _arr = value;
5087             }
5088         }
5089 
5090         public dynamic Obj;
5091     }
5092 
5093     public class Test
5094     {
5095         [Fact]
DynamicCSharpRunTest()5096         public static void DynamicCSharpRunTest()
5097         {
5098             Assert.Equal(0, MainMethod(null));
5099         }
5100 
MainMethod(string[] args)5101         public static int MainMethod(string[] args)
5102         {
5103             int myInt = 3;
5104             string myString = "foo";
5105             int?[] myNullArr = new int?[]
5106             {
5107             1, null
5108             }
5109 
5110             ;
5111             decimal[] myArr = new decimal[]
5112             {
5113             decimal.MaxValue, decimal.One
5114             }
5115 
5116             ;
5117             MyClass mc = new MyClass()
5118             {
5119                 Field = myInt,
5120                 Prop = myString,
5121                 NullArray = myNullArr,
5122                 Array = myArr,
5123                 Obj = myInt
5124             }
5125 
5126             ;
5127             if ((int)mc.Field != 3)
5128                 return 1;
5129             if ((string)mc.Prop != "foo")
5130                 return 1;
5131             if (((int?[])mc.NullArray).Length != 2 || ((int?[])mc.NullArray)[1] != null)
5132                 return 1;
5133             if (((decimal[])mc.Array).Length != 2 || ((decimal[])mc.Array)[0] != decimal.MaxValue)
5134                 return 1;
5135             if ((int)mc.Obj != 3)
5136                 return 1;
5137             return 0;
5138         }
5139     }
5140     // </Code>
5141 }
5142 
5143 
5144 
5145 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.negboxing002.negboxing002
5146 {
5147     public class Test
5148     {
5149         [Fact]
DynamicCSharpRunTest()5150         public static void DynamicCSharpRunTest()
5151         {
5152             Assert.Equal(0, MainMethod(null));
5153         }
5154 
MainMethod(string[] args)5155         public static int MainMethod(string[] args)
5156         {
5157             //int
5158             object o = int.MinValue;
5159             dynamic d = (int)o;
5160             if (d != int.MinValue)
5161                 return 1;
5162             //short
5163             o = short.MaxValue;
5164             d = (short)o;
5165             if (d != short.MaxValue)
5166                 return 1;
5167             //sbyte
5168             o = sbyte.MaxValue;
5169             d = (sbyte)o;
5170             if (d != sbyte.MaxValue)
5171                 return 1;
5172             //long
5173             o = long.MaxValue;
5174             d = (long)o;
5175             if (d != long.MaxValue)
5176                 return 1;
5177             //byte
5178             o = byte.MaxValue;
5179             d = (byte)o;
5180             if (d != byte.MaxValue)
5181                 return 1;
5182             //ushort
5183             o = ushort.MaxValue;
5184             d = (ushort)o;
5185             if (d != ushort.MaxValue)
5186                 return 1;
5187             //ulong
5188             o = ulong.MaxValue;
5189             d = (ulong)o;
5190             if (d != ulong.MaxValue)
5191                 return 1;
5192             //uint
5193             o = uint.MinValue;
5194             d = (uint)o;
5195             if (d != uint.MinValue)
5196                 return 1;
5197             //char
5198             o = 'a';
5199             d = (char)o;
5200             if (d != 'a')
5201                 return 1;
5202             //float
5203             o = float.Epsilon;
5204             d = (float)o;
5205             if (d != float.Epsilon)
5206                 return 1;
5207             o = float.NegativeInfinity;
5208             d = (float)o;
5209             if (!float.IsNegativeInfinity(d))
5210                 return 1;
5211             //double
5212             o = double.MaxValue;
5213             d = (double)o;
5214             if (d != double.MaxValue)
5215                 return 1;
5216             //decimal
5217             o = decimal.MaxValue;
5218             d = (decimal)o;
5219             if (d != decimal.MaxValue)
5220                 return 1;
5221             //bool
5222             o = true;
5223             d = (bool)o;
5224             if (d != true)
5225                 return 1;
5226             //UD enum
5227             o = myEnum.One;
5228             d = (myEnum)o;
5229             if (d != myEnum.One)
5230                 return 1;
5231             //UD struct
5232             o = new myStruct()
5233             {
5234                 field = 1
5235             }
5236 
5237             ;
5238             d = (myStruct)o;
5239             if (d.field != 1)
5240                 return 1;
5241             return 0;
5242         }
5243 
5244         public enum myEnum
5245         {
5246             One
5247         }
5248 
5249         public struct myStruct
5250         {
5251             public int field;
5252         }
5253     }
5254     // </Code>
5255 }
5256 
5257 
5258 
5259 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.nullcoalesce001.nullcoalesce001
5260 {
5261     // <Title>Null coalescing</Title>
5262     // <Description>
5263     // </Description>
5264     // <RelatedBugs></RelatedBugs>
5265     //<Expects Status=success></Expects>
5266     // <Code>
5267     public class MyClass
5268     {
Get()5269         public dynamic Get()
5270         {
5271             return null;
5272         }
5273     }
5274 
5275     public class Test
5276     {
5277         [Fact]
DynamicCSharpRunTest()5278         public static void DynamicCSharpRunTest()
5279         {
5280             Assert.Equal(0, MainMethod(null));
5281         }
5282 
MainMethod(string[] args)5283         public static int MainMethod(string[] args)
5284         {
5285             dynamic d = new MyClass();
5286             var x = d.Get() ?? new object();
5287             return x == null ? 1 : 0;
5288         }
5289     }
5290     // </Code>
5291 }
5292 
5293 
5294 
5295 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.unsfe001.unsfe001
5296 {
5297     // <Title>stackalloc and dynamic</Title>
5298     // <Description>
5299     // </Description>
5300     // <RelatedBugs></RelatedBugs>
5301     //<Expects Status=success></Expects>
5302     // <Code>
5303     //class B
5304     //{
5305     //[Test][Priority(Priority.Priority2)]public void DynamicCSharpRunTest(){Assert.AreEqual(0, MainMethod());} public static unsafe int MainMethod()
5306     //{
5307     ////basic alloc
5308     //dynamic y = 1;
5309     //int* x = stackalloc int[y];
5310     //*x = 3;
5311     //if (*x != 3)
5312     //return 1;
5313     ////alloc with conversion from char
5314     //y = 'a';
5315     //try{
5316     //float* z = stackalloc float[y];
5317     //}
5318     //catch(System.Exception ex){
5319     //System.Console.WriteLine(ex);
5320     //return 1;
5321     //}
5322     ////alloc with operator
5323     //y = 'b';
5324     //try{
5325     //float* z = stackalloc float[ y - 'a'];
5326     //*z = 34f;
5327     //if (*z != 34)
5328     //return 1;
5329     //}
5330     //catch(System.Exception ex){
5331     //System.Console.WriteLine(ex);
5332     //return 1;
5333     //}
5334     ////alloc with return from a method call
5335     //dynamic b = new B();
5336     //try{
5337     //decimal* z = stackalloc decimal[b.GetFloatValue()];
5338     //}
5339     //catch(Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e){
5340     //if (!ErrorVerifier.Verify(ErrorMessageId.NoImplicitConvCast, e.Message, "float", "int"))
5341     //return 1;
5342     //}
5343     ////alloc with return from indexer
5344     //sbyte* t = stackalloc sbyte[b[3]];
5345     ////alloc with return from property
5346     //sbyte* u = stackalloc sbyte[b.prop];
5347     //return 0;
5348     //}
5349     //public dynamic GetFloatValue(){ return 12.4f; }
5350     //public int this[byte index]{ get{ return index;} }
5351     //public int prop {get {return 4;} }
5352     //}
5353     // </Code>
5354 }
5355 
5356 
5357 
5358 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.query003.query003
5359 {
5360     // <Title>Query expression</Title>
5361     // <Description>
5362     // </Description>
5363     // <RelatedBugs></RelatedBugs>
5364     //<Expects Status=success></Expects>
5365     // <Code>
5366     using System.Collections.Generic;
5367     using System.Linq;
5368 
5369     public class Test
5370     {
5371         [Fact]
DynamicCSharpRunTest()5372         public static void DynamicCSharpRunTest()
5373         {
5374             Assert.Equal(0, MainMethod(null));
5375         }
5376 
MainMethod(string[] args)5377         public static int MainMethod(string[] args)
5378         {
5379             dynamic d = 3;
5380             var list = new List<int>
5381             {
5382             1, 2, 3
5383             }
5384 
5385             ;
5386             var x =
5387                 from c in list
5388                 where c == (int)d
5389                 select c;
5390             if (x.Count() != 1)
5391                 return 1;
5392             return 0;
5393         }
5394     }
5395     // </Code>
5396 }
5397 
5398 
5399 
5400 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.query004.query004
5401 {
5402     // <Title>Query expression</Title>
5403     // <Description>
5404     // </Description>
5405     // <RelatedBugs></RelatedBugs>
5406     //<Expects Status=success></Expects>
5407     // <Code>
5408     using System.Collections.Generic;
5409     using System.Linq;
5410 
5411     public class myClass
5412     {
Transform(int x)5413         public int Transform(int x)
5414         {
5415             return x + 1;
5416         }
5417     }
5418 
5419     public class Test
5420     {
5421         [Fact]
DynamicCSharpRunTest()5422         public static void DynamicCSharpRunTest()
5423         {
5424             Assert.Equal(0, MainMethod(null));
5425         }
5426 
MainMethod(string[] args)5427         public static int MainMethod(string[] args)
5428         {
5429             dynamic d = new myClass();
5430             var list = new List<int>
5431             {
5432             1, 2, 3
5433             }
5434 
5435             ;
5436             var x = (
5437                 from c in list
5438                 where c == 2
5439                 select d.Transform(c)).SingleOrDefault();
5440             if ((int)x != 3)
5441                 return 1;
5442             return 0;
5443         }
5444     }
5445     // </Code>
5446 }
5447 
5448 
5449 
5450 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.query005.query005
5451 {
5452     // <Title>Query expression</Title>
5453     // <Description>
5454     // </Description>
5455     // <RelatedBugs></RelatedBugs>
5456     //<Expects Status=success></Expects>
5457     // <Code>
5458     using System.Collections.Generic;
5459     using System.Linq;
5460 
5461     public class myClass
5462     {
Transform(int x)5463         public int Transform(int x)
5464         {
5465             return x + 1;
5466         }
5467     }
5468 
5469     public class Test
5470     {
5471         [Fact]
DynamicCSharpRunTest()5472         public static void DynamicCSharpRunTest()
5473         {
5474             Assert.Equal(0, MainMethod(null));
5475         }
5476 
MainMethod(string[] args)5477         public static int MainMethod(string[] args)
5478         {
5479             dynamic d = new myClass();
5480             var list = new List<int>
5481             {
5482             1, 2, 3
5483             }
5484 
5485             ;
5486             var x = (
5487                 from c in list
5488                 where c == 2
5489                 orderby d.Transform(c)
5490                 select d.Transform(c)).SingleOrDefault();
5491             if ((int)x != 3)
5492                 return 1;
5493             return 0;
5494         }
5495     }
5496     // </Code>
5497 }
5498 
5499 
5500 
5501 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.throw003.throw003
5502 {
5503     // <Title>Throw</Title>
5504     // <Description>
5505     // </Description>
5506     // <RelatedBugs></RelatedBugs>
5507     //<Expects Status=success></Expects>
5508     // <Code>
5509     public class D
5510     {
5511         public void Foo<T>(T t) where T : System.Exception
5512         {
5513             throw t;
5514         }
5515     }
5516 
5517     public class C
5518     {
5519         [Fact]
DynamicCSharpRunTest()5520         public static void DynamicCSharpRunTest()
5521         {
5522             Assert.Equal(0, MainMethod());
5523         }
5524 
MainMethod()5525         public static int MainMethod()
5526         {
5527             dynamic d = new D();
5528             dynamic d2 = 3;
5529             try
5530             {
5531                 d.Foo(d2);
5532             }
5533             catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
5534             {
5535                 if (ErrorVerifier.Verify(ErrorMessageId.GenericConstraintNotSatisfiedValType, e.Message, "D.Foo<T>(T)", "System.Exception", "T", "int"))
5536                     return 0;
5537             }
5538 
5539             return 1;
5540         }
5541     }
5542     // </Code>
5543 }
5544 
5545 
5546 
5547 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.common.common
5548 {
5549     // <Title> Dynamic and static interaction utility class </Title>
5550     // <Description>
5551     // </Description>
5552     // <RelatedBugs></RelatedBugs>
5553     // <Expects Status=success></Expects>
5554     // <Code>
5555     using System;
5556 
5557     public class Verify
5558     {
Eval(Func<bool> testmethod, string comment = null)5559         internal static int Eval(Func<bool> testmethod, string comment = null)
5560         {
5561             int result = 0;
5562             try
5563             {
5564                 if (!testmethod())
5565                 {
5566                     result++;
5567                 }
5568             }
5569             catch (Exception e)
5570             {
5571                 result++;
5572             }
5573 
5574             return result;
5575         }
5576     }
5577     // </Code>
5578 }
5579 
5580 
5581 
5582 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate001.operate001
5583 {
5584     using ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.common.common;
5585     // <Title> Operator -.</Title>
5586     // <Description>
5587     // </Description>
5588     // <RelatedBugs></RelatedBugs>
5589     //<Expects Status=success></Expects>
5590     // <Code>
5591 
5592     public class Test
5593     {
5594         private enum MyEnum
5595         {
5596             First,
5597             Second,
5598             Third
5599         }
5600 
5601         [Fact]
DynamicCSharpRunTest()5602         public static void DynamicCSharpRunTest()
5603         {
5604             Assert.Equal(0, MainMethod());
5605         }
5606 
MainMethod()5607         public static int MainMethod()
5608         {
5609             int result = 0;
5610             result += Verify.Eval(Test1);
5611             result += Verify.Eval(Test2);
5612             result += Verify.Eval(Test3);
5613             result += Verify.Eval(Test4);
5614             result += Verify.Eval(Test5);
5615             result += Verify.Eval(Test6);
5616             result += Verify.Eval(Test7);
5617             return result;
5618         }
5619 
Test1()5620         private static bool Test1()
5621         {
5622             dynamic a = 10;
5623             int b = -a;
5624             if (b == -10)
5625                 return true;
5626             System.Console.WriteLine("Failed -- -int");
5627             return false;
5628         }
5629 
Test2()5630         private static bool Test2()
5631         {
5632             dynamic a = 10L;
5633             long b = -(-a);
5634             if (b == 10)
5635                 return true;
5636             System.Console.WriteLine("Failed -- -long");
5637             return false;
5638         }
5639 
Test3()5640         private static bool Test3()
5641         {
5642             dynamic a = 10.10f;
5643             float b = -a;
5644             if (b == -10.10f)
5645                 return true;
5646             System.Console.WriteLine("Failed -- -float");
5647             return false;
5648         }
5649 
Test4()5650         private static bool Test4()
5651         {
5652             dynamic a = 10.10d;
5653             double b = -a;
5654             if (b == -10.10)
5655                 return true;
5656             System.Console.WriteLine("Failed -- -double");
5657             return false;
5658         }
5659 
Test5()5660         private static bool Test5()
5661         {
5662             dynamic a = 10.001M;
5663             decimal b = -a;
5664             if (b == -10.001M)
5665                 return true;
5666             System.Console.WriteLine("Failed -- -decimal");
5667             return false;
5668         }
5669 
Test6()5670         private static bool Test6()
5671         {
5672             uint i = 10;
5673             dynamic a = i;
5674             try
5675             {
5676                 int b = -a; //no - operator on uint.
5677             }
5678             catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
5679             {
5680                 if (ErrorVerifier.Verify(ErrorMessageId.NoImplicitConvCast, e.Message, "long", "int"))
5681                     return true;
5682             }
5683 
5684             return false;
5685         }
5686 
Test7()5687         private static bool Test7()
5688         {
5689             dynamic a = MyEnum.First;
5690             try
5691             {
5692                 MyEnum b = -a; //no - operator on enum.
5693             }
5694             catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
5695             {
5696                 if (ErrorVerifier.Verify(ErrorMessageId.BadUnaryOp, e.Message, "-", "Test.MyEnum"))
5697                     return true;
5698             }
5699 
5700             return false;
5701         }
5702     }
5703     //</Code>
5704 }
5705 
5706 
5707 
5708 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate002.operate002
5709 {
5710     using ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.common.common;
5711     // <Title> Operator +.</Title>
5712     // <Description>
5713     // </Description>
5714     // <RelatedBugs></RelatedBugs>
5715     //<Expects Status=success></Expects>
5716     // <Code>
5717 
5718     public class Test
5719     {
5720         private enum MyEnum
5721         {
5722             First,
5723             Second,
5724             Third
5725         }
5726 
5727         [Fact]
DynamicCSharpRunTest()5728         public static void DynamicCSharpRunTest()
5729         {
5730             Assert.Equal(0, MainMethod());
5731         }
5732 
MainMethod()5733         public static int MainMethod()
5734         {
5735             int result = 0;
5736             result += Verify.Eval(Test1);
5737             result += Verify.Eval(Test2);
5738             result += Verify.Eval(Test3);
5739             result += Verify.Eval(Test4);
5740             result += Verify.Eval(Test5);
5741             result += Verify.Eval(Test6);
5742             result += Verify.Eval(Test7);
5743             return result;
5744         }
5745 
Test1()5746         private static bool Test1()
5747         {
5748             dynamic a = -10;
5749             int b = +a;
5750             if (b == -10)
5751                 return true;
5752             System.Console.WriteLine("Failed -- +int");
5753             return false;
5754         }
5755 
Test2()5756         private static bool Test2()
5757         {
5758             dynamic a = -10L;
5759             long b = +(+a);
5760             if (b == -10)
5761                 return true;
5762             System.Console.WriteLine("Failed -- +long");
5763             return false;
5764         }
5765 
Test3()5766         private static bool Test3()
5767         {
5768             dynamic a = 10.10f;
5769             float b = +a;
5770             if (b == 10.10f)
5771                 return true;
5772             System.Console.WriteLine("Failed -- +float");
5773             return false;
5774         }
5775 
Test4()5776         private static bool Test4()
5777         {
5778             dynamic a = 10.10d;
5779             double b = +(-a);
5780             if (b == -10.10)
5781                 return true;
5782             System.Console.WriteLine("Failed -- +double");
5783             return false;
5784         }
5785 
Test5()5786         private static bool Test5()
5787         {
5788             dynamic a = -10.001M;
5789             decimal b = +a;
5790             if (b == -10.001M)
5791                 return true;
5792             System.Console.WriteLine("Failed -- +decimal");
5793             return false;
5794         }
5795 
Test6()5796         private static bool Test6()
5797         {
5798             string i = "10";
5799             dynamic a = i;
5800             try
5801             {
5802                 int b = +a; //no + operator on string.
5803             }
5804             catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
5805             {
5806                 if (ErrorVerifier.Verify(ErrorMessageId.BadUnaryOp, e.Message, "+", "string"))
5807                     return true;
5808             }
5809 
5810             return false;
5811         }
5812 
Test7()5813         private static bool Test7()
5814         {
5815             dynamic a = MyEnum.Second;
5816             try
5817             {
5818                 MyEnum b = +a; //no + operator on enum.
5819             }
5820             catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
5821             {
5822                 if (ErrorVerifier.Verify(ErrorMessageId.BadUnaryOp, e.Message, "+", "Test.MyEnum"))
5823                     return true;
5824             }
5825 
5826             return false;
5827         }
5828     }
5829     //</Code>
5830 }
5831 
5832 
5833 
5834 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate003.operate003
5835 {
5836     using ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.common.common;
5837     // <Title> Operator ~.</Title>
5838     // <Description>
5839     // </Description>
5840     // <RelatedBugs></RelatedBugs>
5841     //<Expects Status=success></Expects>
5842     // <Code>
5843 
5844     public class Test
5845     {
5846         public enum MyEnum
5847         {
5848             First,
5849             Second,
5850             Third
5851         }
5852 
5853         [Fact]
DynamicCSharpRunTest()5854         public static void DynamicCSharpRunTest()
5855         {
5856             Assert.Equal(0, MainMethod());
5857         }
5858 
MainMethod()5859         public static int MainMethod()
5860         {
5861             int result = 0;
5862             result += Verify.Eval(Test1);
5863             result += Verify.Eval(Test2);
5864             result += Verify.Eval(Test3);
5865             result += Verify.Eval(Test4);
5866             result += Verify.Eval(Test5);
5867             result += Verify.Eval(Test6);
5868             return result;
5869         }
5870 
Test1()5871         private static bool Test1()
5872         {
5873             dynamic a = 10;
5874             int b = ~a;
5875             if (b == -11)
5876                 return true;
5877             System.Console.WriteLine("Failed -- ~int");
5878             return false;
5879         }
5880 
Test2()5881         private static bool Test2()
5882         {
5883             dynamic a = -10L;
5884             long b = ~a;
5885             if (b == 9)
5886                 return true;
5887             System.Console.WriteLine("Failed -- ~long");
5888             return false;
5889         }
5890 
Test3()5891         private static bool Test3()
5892         {
5893             dynamic a = uint.MinValue;
5894             uint b = ~a;
5895             if (b == uint.MaxValue)
5896                 return true;
5897             System.Console.WriteLine("Failed -- ~uint");
5898             return false;
5899         }
5900 
Test4()5901         private static bool Test4()
5902         {
5903             dynamic a = ulong.MaxValue;
5904             ulong b = ~~a;
5905             if (b == ulong.MaxValue)
5906                 return true;
5907             System.Console.WriteLine("Failed -- ~ulong");
5908             return false;
5909         }
5910 
Test5()5911         private static bool Test5()
5912         {
5913             dynamic a = MyEnum.Second;
5914             MyEnum b = ~a;
5915             if (b == ~MyEnum.Second)
5916                 return true;
5917             System.Console.WriteLine("Failed -- ~enum");
5918             return false;
5919         }
5920 
Test6()5921         private static bool Test6()
5922         {
5923             dynamic a = "10";
5924             try
5925             {
5926                 int b = ~a; //no ~ operator on string.
5927             }
5928             catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
5929             {
5930                 if (ErrorVerifier.Verify(ErrorMessageId.BadUnaryOp, e.Message, "~", "string"))
5931                     return true;
5932             }
5933 
5934             System.Console.WriteLine("Failed -- ~string");
5935             return false;
5936         }
5937     }
5938     //</Code>
5939 }
5940 
5941 
5942 
5943 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate004.operate004
5944 {
5945     using ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.common.common;
5946     // <Title> Operator !.</Title>
5947     // <Description>
5948     // </Description>
5949     // <RelatedBugs></RelatedBugs>
5950     //<Expects Status=success></Expects>
5951     // <Code>
5952 
5953     public class Test
5954     {
5955         [Fact]
DynamicCSharpRunTest()5956         public static void DynamicCSharpRunTest()
5957         {
5958             Assert.Equal(0, MainMethod());
5959         }
5960 
MainMethod()5961         public static int MainMethod()
5962         {
5963             int result = 0;
5964             result += Verify.Eval(Test1);
5965             result += Verify.Eval(Test2);
5966             result += Verify.Eval(Test3);
5967             return result;
5968         }
5969 
Test1()5970         private static bool Test1()
5971         {
5972             bool[] boolValues = new bool[]
5973             {
5974             true, false
5975             }
5976 
5977             ;
5978             foreach (bool a in boolValues)
5979             {
5980                 dynamic d = a;
5981                 if (!d != !a)
5982                 {
5983                     System.Console.WriteLine("Failed -- !bool");
5984                     return false;
5985                 }
5986             }
5987 
5988             return true;
5989         }
5990 
Test2()5991         private static bool Test2()
5992         {
5993             bool?[] boolValues = new bool?[]
5994             {
5995             true, false
5996             };
5997 
5998             foreach (bool? a in boolValues)
5999             {
6000                 dynamic d = a;
6001                 if (!d != !a)
6002                 {
6003                     System.Console.WriteLine("Failed -- !Nullable<bool>");
6004                     return false;
6005                 }
6006             }
6007 
6008             return true;
6009         }
6010 
Test3()6011         private static bool Test3()
6012         {
6013             dynamic a = "10";
6014             try
6015             {
6016                 int b = !a; //no ! operator on string.
6017             }
6018             catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
6019             {
6020                 if (ErrorVerifier.Verify(ErrorMessageId.BadUnaryOp, e.Message, "!", "string"))
6021                     return true;
6022             }
6023 
6024             return false;
6025         }
6026     }
6027     //</Code>
6028 }
6029 
6030 
6031 
6032 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate005.operate005
6033 {
6034     using ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.common.common;
6035     // <Title> Operator ++.</Title>
6036     // <Description>
6037     // </Description>
6038     // <RelatedBugs></RelatedBugs>
6039     //<Expects Status=success></Expects>
6040     // <Code>
6041 
6042     public class Test
6043     {
6044         public enum MyEnum
6045         {
6046             First,
6047             Second,
6048             Third
6049         }
6050 
6051         [Fact]
DynamicCSharpRunTest()6052         public static void DynamicCSharpRunTest()
6053         {
6054             Assert.Equal(0, MainMethod());
6055         }
6056 
MainMethod()6057         public static int MainMethod()
6058         {
6059             int result = 0;
6060             result += Verify.Eval(Test1);
6061             result += Verify.Eval(Test2);
6062             result += Verify.Eval(Test3);
6063             result += Verify.Eval(Test4);
6064             result += Verify.Eval(Test5);
6065             result += Verify.Eval(Test6);
6066             result += Verify.Eval(Test7);
6067             result += Verify.Eval(Test8);
6068             result += Verify.Eval(Test9);
6069             result += Verify.Eval(Test10);
6070             result += Verify.Eval(Test11);
6071             result += Verify.Eval(Test12);
6072             result += Verify.Eval(Test13);
6073             result += Verify.Eval(Test14);
6074             return result;
6075         }
6076 
Test1()6077         private static bool Test1()
6078         {
6079             sbyte a = 10;
6080             dynamic b = a;
6081             ++b;
6082             if (b == 11)
6083                 return true;
6084             System.Console.WriteLine("Failed -- ++sbyte");
6085             return false;
6086         }
6087 
Test2()6088         private static bool Test2()
6089         {
6090             byte a = 10;
6091             dynamic b = a;
6092             ++b;
6093             if (b == 11)
6094                 return true;
6095             System.Console.WriteLine("Failed -- ++byte");
6096             return false;
6097         }
6098 
Test3()6099         private static bool Test3()
6100         {
6101             short a = 1;
6102             dynamic b = a;
6103             ++b;
6104             if (b == 2)
6105                 return true;
6106             System.Console.WriteLine("Failed -- ++short");
6107             return false;
6108         }
6109 
Test4()6110         private static bool Test4()
6111         {
6112             ushort a = 1;
6113             dynamic b = a;
6114             ++b;
6115             if (b == 2)
6116                 return true;
6117             System.Console.WriteLine("Failed -- ++ushort");
6118             return false;
6119         }
6120 
Test5()6121         private static bool Test5()
6122         {
6123             int a = -1;
6124             dynamic b = a;
6125             ++b;
6126             if (b == 0)
6127                 return true;
6128             System.Console.WriteLine("Failed -- ++int");
6129             return false;
6130         }
6131 
Test6()6132         private static bool Test6()
6133         {
6134             uint a = 1;
6135             dynamic b = a;
6136             ++b;
6137             if (b == 2)
6138                 return true;
6139             System.Console.WriteLine("Failed -- ++uint");
6140             return false;
6141         }
6142 
Test7()6143         private static bool Test7()
6144         {
6145             long a = 1;
6146             dynamic b = a;
6147             ++b;
6148             if (b == 2)
6149                 return true;
6150             System.Console.WriteLine("Failed -- ++long");
6151             return false;
6152         }
6153 
Test8()6154         private static bool Test8()
6155         {
6156             ulong a = 1;
6157             dynamic b = a;
6158             ++b;
6159             if (b == 2)
6160                 return true;
6161             System.Console.WriteLine("Failed -- ++ulong");
6162             return false;
6163         }
6164 
Test9()6165         private static bool Test9()
6166         {
6167             char a = 'a';
6168             dynamic b = a;
6169             ++b;
6170             if (b == 'b')
6171                 return true;
6172             System.Console.WriteLine("Failed -- ++char");
6173             return false;
6174         }
6175 
Test10()6176         private static bool Test10()
6177         {
6178             float a = 1.10f;
6179             dynamic b = a;
6180             ++b;
6181             if (b == 2.10f)
6182                 return true;
6183             System.Console.WriteLine("Failed -- ++float");
6184             return false;
6185         }
6186 
Test11()6187         private static bool Test11()
6188         {
6189             double a = 1.10d;
6190             dynamic b = a;
6191             ++b;
6192             if (b == 2.10d)
6193                 return true;
6194             System.Console.WriteLine("Failed -- ++double");
6195             return false;
6196         }
6197 
Test12()6198         private static bool Test12()
6199         {
6200             decimal a = 1.10M;
6201             dynamic b = a;
6202             ++b;
6203             if (b == 2.10M)
6204                 return true;
6205             System.Console.WriteLine("Failed -- ++decimal");
6206             return false;
6207         }
6208 
Test13()6209         private static bool Test13()
6210         {
6211             MyEnum a = MyEnum.Second;
6212             dynamic b = a;
6213             ++b;
6214             if (b == MyEnum.Third)
6215                 return true;
6216             System.Console.WriteLine("Failed -- ++enum");
6217             return false;
6218         }
6219 
Test14()6220         private static bool Test14()
6221         {
6222             dynamic a = "10";
6223             try
6224             {
6225                 ++a; //no ++ operator on string.
6226             }
6227             catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
6228             {
6229                 if (ErrorVerifier.Verify(ErrorMessageId.BadUnaryOp, e.Message, "++", "string"))
6230                     return true;
6231             }
6232 
6233             return false;
6234         }
6235     }
6236     //</Code>
6237 }
6238 
6239 
6240 
6241 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate005a.operate005a
6242 {
6243     using ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.common.common;
6244     // <Title> Operator ++.</Title>
6245     // <Description>
6246     // </Description>
6247     // <RelatedBugs></RelatedBugs>
6248     //<Expects Status=success></Expects>
6249     // <Code>
6250 
6251     public class Test
6252     {
6253         public enum MyEnum
6254         {
6255             First,
6256             Second,
6257             Third
6258         }
6259 
6260         [Fact]
DynamicCSharpRunTest()6261         public static void DynamicCSharpRunTest()
6262         {
6263             Assert.Equal(0, MainMethod());
6264         }
6265 
MainMethod()6266         public static int MainMethod()
6267         {
6268             int result = 0;
6269             result += Verify.Eval(Test1);
6270             result += Verify.Eval(Test2);
6271             result += Verify.Eval(Test3);
6272             result += Verify.Eval(Test4);
6273             result += Verify.Eval(Test5);
6274             result += Verify.Eval(Test6);
6275             result += Verify.Eval(Test7);
6276             result += Verify.Eval(Test8);
6277             result += Verify.Eval(Test9);
6278             result += Verify.Eval(Test10);
6279             result += Verify.Eval(Test11);
6280             result += Verify.Eval(Test12);
6281             result += Verify.Eval(Test13);
6282             result += Verify.Eval(Test14);
6283             return result;
6284         }
6285 
Test1()6286         private static bool Test1()
6287         {
6288             sbyte a = 10;
6289             dynamic b = a;
6290             b++;
6291             if (b == 11)
6292                 return true;
6293             System.Console.WriteLine("Failed -- ++sbyte");
6294             return false;
6295         }
6296 
Test2()6297         private static bool Test2()
6298         {
6299             byte a = 10;
6300             dynamic b = a;
6301             b++;
6302             if (b == 11)
6303                 return true;
6304             System.Console.WriteLine("Failed -- b++yte");
6305             return false;
6306         }
6307 
Test3()6308         private static bool Test3()
6309         {
6310             short a = 1;
6311             dynamic b = a;
6312             b++;
6313             if (b == 2)
6314                 return true;
6315             System.Console.WriteLine("Failed -- ++short");
6316             return false;
6317         }
6318 
Test4()6319         private static bool Test4()
6320         {
6321             ushort a = 1;
6322             dynamic b = a;
6323             b++;
6324             if (b == 2)
6325                 return true;
6326             System.Console.WriteLine("Failed -- ++ushort");
6327             return false;
6328         }
6329 
Test5()6330         private static bool Test5()
6331         {
6332             int a = -1;
6333             dynamic b = a;
6334             b++;
6335             if (b == 0)
6336                 return true;
6337             System.Console.WriteLine("Failed -- ++int");
6338             return false;
6339         }
6340 
Test6()6341         private static bool Test6()
6342         {
6343             uint a = 1;
6344             dynamic b = a;
6345             b++;
6346             if (b == 2)
6347                 return true;
6348             System.Console.WriteLine("Failed -- ++uint");
6349             return false;
6350         }
6351 
Test7()6352         private static bool Test7()
6353         {
6354             long a = 1;
6355             dynamic b = a;
6356             b++;
6357             if (b == 2)
6358                 return true;
6359             System.Console.WriteLine("Failed -- ++long");
6360             return false;
6361         }
6362 
Test8()6363         private static bool Test8()
6364         {
6365             ulong a = 1;
6366             dynamic b = a;
6367             b++;
6368             if (b == 2)
6369                 return true;
6370             System.Console.WriteLine("Failed -- ++ulong");
6371             return false;
6372         }
6373 
Test9()6374         private static bool Test9()
6375         {
6376             char a = 'a';
6377             dynamic b = a;
6378             b++;
6379             if (b == 'b')
6380                 return true;
6381             System.Console.WriteLine("Failed -- ++char");
6382             return false;
6383         }
6384 
Test10()6385         private static bool Test10()
6386         {
6387             float a = 1.10f;
6388             dynamic b = a;
6389             b++;
6390             if (b == 2.10f)
6391                 return true;
6392             System.Console.WriteLine("Failed -- ++float");
6393             return false;
6394         }
6395 
Test11()6396         private static bool Test11()
6397         {
6398             double a = 1.10d;
6399             dynamic b = a;
6400             b++;
6401             if (b == 2.10d)
6402                 return true;
6403             System.Console.WriteLine("Failed -- ++double");
6404             return false;
6405         }
6406 
Test12()6407         private static bool Test12()
6408         {
6409             decimal a = 1.10M;
6410             dynamic b = a;
6411             b++;
6412             if (b == 2.10M)
6413                 return true;
6414             System.Console.WriteLine("Failed -- ++decimal");
6415             return false;
6416         }
6417 
Test13()6418         private static bool Test13()
6419         {
6420             MyEnum a = MyEnum.Second;
6421             dynamic b = a;
6422             b++;
6423             if (b == MyEnum.Third)
6424                 return true;
6425             System.Console.WriteLine("Failed -- ++enum");
6426             return false;
6427         }
6428 
Test14()6429         private static bool Test14()
6430         {
6431             dynamic a = "10";
6432             try
6433             {
6434                 a++; //no ++ operator on string.
6435             }
6436             catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
6437             {
6438                 if (ErrorVerifier.Verify(ErrorMessageId.BadUnaryOp, e.Message, "++", "string"))
6439                     return true;
6440             }
6441 
6442             return false;
6443         }
6444     }
6445     //</Code>
6446 }
6447 
6448 
6449 
6450 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate006.operate006
6451 {
6452     using ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.common.common;
6453     // <Title> Operator --.</Title>
6454     // <Description>
6455     // </Description>
6456     // <RelatedBugs></RelatedBugs>
6457     //<Expects Status=success></Expects>
6458     // <Code>
6459 
6460     public class Test
6461     {
6462         public enum MyEnum
6463         {
6464             First,
6465             Second,
6466             Third
6467         }
6468 
6469         [Fact]
DynamicCSharpRunTest()6470         public static void DynamicCSharpRunTest()
6471         {
6472             Assert.Equal(0, MainMethod());
6473         }
6474 
MainMethod()6475         public static int MainMethod()
6476         {
6477             int result = 0;
6478             result += Verify.Eval(Test1);
6479             result += Verify.Eval(Test2);
6480             result += Verify.Eval(Test3);
6481             result += Verify.Eval(Test4);
6482             result += Verify.Eval(Test5);
6483             result += Verify.Eval(Test6);
6484             result += Verify.Eval(Test7);
6485             result += Verify.Eval(Test8);
6486             result += Verify.Eval(Test9);
6487             result += Verify.Eval(Test10);
6488             result += Verify.Eval(Test11);
6489             result += Verify.Eval(Test12);
6490             result += Verify.Eval(Test13);
6491             result += Verify.Eval(Test14);
6492             return result;
6493         }
6494 
Test1()6495         private static bool Test1()
6496         {
6497             sbyte a = 10;
6498             dynamic b = a;
6499             --b;
6500             if (b == 9)
6501                 return true;
6502             System.Console.WriteLine("Failed -- --sbyte");
6503             return false;
6504         }
6505 
Test2()6506         private static bool Test2()
6507         {
6508             byte a = 10;
6509             dynamic b = a;
6510             --b;
6511             if (b == 9)
6512                 return true;
6513             System.Console.WriteLine("Failed -- --byte");
6514             return false;
6515         }
6516 
Test3()6517         private static bool Test3()
6518         {
6519             short a = 2;
6520             dynamic b = a;
6521             --b;
6522             if (b == 1)
6523                 return true;
6524             System.Console.WriteLine("Failed -- --short");
6525             return false;
6526         }
6527 
Test4()6528         private static bool Test4()
6529         {
6530             ushort a = 2;
6531             dynamic b = a;
6532             --b;
6533             if (b == 1)
6534                 return true;
6535             System.Console.WriteLine("Failed -- --ushort");
6536             return false;
6537         }
6538 
Test5()6539         private static bool Test5()
6540         {
6541             int a = -1;
6542             dynamic b = a;
6543             --b;
6544             if (b == -2)
6545                 return true;
6546             System.Console.WriteLine("Failed -- --int");
6547             return false;
6548         }
6549 
Test6()6550         private static bool Test6()
6551         {
6552             uint a = 1;
6553             dynamic b = a;
6554             --b;
6555             if (b == 0)
6556                 return true;
6557             System.Console.WriteLine("Failed -- --uint");
6558             return false;
6559         }
6560 
Test7()6561         private static bool Test7()
6562         {
6563             long a = 1;
6564             dynamic b = a;
6565             --b;
6566             if (b == 0)
6567                 return true;
6568             System.Console.WriteLine("Failed -- --long");
6569             return false;
6570         }
6571 
Test8()6572         private static bool Test8()
6573         {
6574             ulong a = 2;
6575             dynamic b = a;
6576             --b;
6577             if (b == 1)
6578                 return true;
6579             System.Console.WriteLine("Failed -- --ulong");
6580             return false;
6581         }
6582 
Test9()6583         private static bool Test9()
6584         {
6585             char a = 'b';
6586             dynamic b = a;
6587             --b;
6588             if (b == 'a')
6589                 return true;
6590             System.Console.WriteLine("Failed -- --char");
6591             return false;
6592         }
6593 
Test10()6594         private static bool Test10()
6595         {
6596             float a = 1.11f;
6597             dynamic b = a;
6598             --b;
6599             a--;
6600             if (b == a)
6601                 return true;
6602             System.Console.WriteLine("Failed -- --float");
6603             return false;
6604         }
6605 
Test11()6606         private static bool Test11()
6607         {
6608             double a = 1.12d;
6609             dynamic b = a;
6610             --b;
6611             a--;
6612             if (b == a)
6613                 return true;
6614             System.Console.WriteLine("Failed -- --double");
6615             return false;
6616         }
6617 
Test12()6618         private static bool Test12()
6619         {
6620             decimal a = 2.10M;
6621             dynamic b = a;
6622             --b;
6623             if (b == 1.10M)
6624                 return true;
6625             System.Console.WriteLine("Failed -- --decimal");
6626             return false;
6627         }
6628 
Test13()6629         private static bool Test13()
6630         {
6631             MyEnum a = MyEnum.Third;
6632             dynamic b = a;
6633             --b;
6634             if (b == MyEnum.Second)
6635                 return true;
6636             System.Console.WriteLine("Failed -- --enum");
6637             return false;
6638         }
6639 
Test14()6640         private static bool Test14()
6641         {
6642             dynamic a = "10";
6643             try
6644             {
6645                 --a; //no -- operator on string.
6646             }
6647             catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
6648             {
6649                 if (ErrorVerifier.Verify(ErrorMessageId.BadUnaryOp, e.Message, "--", "string"))
6650                     return true;
6651             }
6652 
6653             return false;
6654         }
6655     }
6656     //</Code>
6657 }
6658 
6659 
6660 
6661 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate006a.operate006a
6662 {
6663     using ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.common.common;
6664     // <Title> Operator --.</Title>
6665     // <Description>
6666     // </Description>
6667     // <RelatedBugs></RelatedBugs>
6668     //<Expects Status=success></Expects>
6669     // <Code>
6670 
6671     public class Test
6672     {
6673         public enum MyEnum
6674         {
6675             First,
6676             Second,
6677             Third
6678         }
6679 
6680         [Fact]
DynamicCSharpRunTest()6681         public static void DynamicCSharpRunTest()
6682         {
6683             Assert.Equal(0, MainMethod());
6684         }
6685 
MainMethod()6686         public static int MainMethod()
6687         {
6688             int result = 0;
6689             result += Verify.Eval(Test1);
6690             result += Verify.Eval(Test2);
6691             result += Verify.Eval(Test3);
6692             result += Verify.Eval(Test4);
6693             result += Verify.Eval(Test5);
6694             result += Verify.Eval(Test6);
6695             result += Verify.Eval(Test7);
6696             result += Verify.Eval(Test8);
6697             result += Verify.Eval(Test9);
6698             result += Verify.Eval(Test10);
6699             result += Verify.Eval(Test11);
6700             result += Verify.Eval(Test12);
6701             result += Verify.Eval(Test13);
6702             result += Verify.Eval(Test14);
6703             return result;
6704         }
6705 
Test1()6706         private static bool Test1()
6707         {
6708             sbyte a = 10;
6709             dynamic b = a;
6710             b--;
6711             if (b == 9)
6712                 return true;
6713             System.Console.WriteLine("Failed -- --sbyte");
6714             return false;
6715         }
6716 
Test2()6717         private static bool Test2()
6718         {
6719             byte a = 10;
6720             dynamic b = a;
6721             b--;
6722             if (b == 9)
6723                 return true;
6724             System.Console.WriteLine("Failed -- b--yte");
6725             return false;
6726         }
6727 
Test3()6728         private static bool Test3()
6729         {
6730             short a = 2;
6731             dynamic b = a;
6732             b--;
6733             if (b == 1)
6734                 return true;
6735             System.Console.WriteLine("Failed -- --short");
6736             return false;
6737         }
6738 
Test4()6739         private static bool Test4()
6740         {
6741             ushort a = 2;
6742             dynamic b = a;
6743             b--;
6744             if (b == 1)
6745                 return true;
6746             System.Console.WriteLine("Failed -- --ushort");
6747             return false;
6748         }
6749 
Test5()6750         private static bool Test5()
6751         {
6752             int a = -1;
6753             dynamic b = a;
6754             b--;
6755             if (b == -2)
6756                 return true;
6757             System.Console.WriteLine("Failed -- --int");
6758             return false;
6759         }
6760 
Test6()6761         private static bool Test6()
6762         {
6763             uint a = 2;
6764             dynamic b = a;
6765             b--;
6766             if (b == 1)
6767                 return true;
6768             System.Console.WriteLine("Failed -- --uint");
6769             return false;
6770         }
6771 
Test7()6772         private static bool Test7()
6773         {
6774             long a = 1;
6775             dynamic b = a;
6776             b--;
6777             if (b == 0)
6778                 return true;
6779             System.Console.WriteLine("Failed -- --long");
6780             return false;
6781         }
6782 
Test8()6783         private static bool Test8()
6784         {
6785             ulong a = 2;
6786             dynamic b = a;
6787             b--;
6788             if (b == 1)
6789                 return true;
6790             System.Console.WriteLine("Failed -- --ulong");
6791             return false;
6792         }
6793 
Test9()6794         private static bool Test9()
6795         {
6796             char a = 'b';
6797             dynamic b = a;
6798             b--;
6799             if (b == 'a')
6800                 return true;
6801             System.Console.WriteLine("Failed -- --char");
6802             return false;
6803         }
6804 
Test10()6805         private static bool Test10()
6806         {
6807             float a = 2.10f;
6808             dynamic b = a;
6809             b--;
6810             --a;
6811             if (b == a)
6812                 return true;
6813             System.Console.WriteLine("Failed -- --float");
6814             return false;
6815         }
6816 
Test11()6817         private static bool Test11()
6818         {
6819             double a = 2.10d;
6820             dynamic b = a;
6821             b--;
6822             if (b == 1.10d)
6823                 return true;
6824             System.Console.WriteLine("Failed -- --double");
6825             return false;
6826         }
6827 
Test12()6828         private static bool Test12()
6829         {
6830             decimal a = 2.10M;
6831             dynamic b = a;
6832             b--;
6833             if (b == 1.10M)
6834                 return true;
6835             System.Console.WriteLine("Failed -- --decimal");
6836             return false;
6837         }
6838 
Test13()6839         private static bool Test13()
6840         {
6841             MyEnum a = MyEnum.Third;
6842             dynamic b = a;
6843             b--;
6844             if (b == MyEnum.Second)
6845                 return true;
6846             System.Console.WriteLine("Failed -- --enum");
6847             return false;
6848         }
6849 
Test14()6850         private static bool Test14()
6851         {
6852             dynamic a = "10";
6853             try
6854             {
6855                 a--; //no -- operator on string.
6856             }
6857             catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
6858             {
6859                 if (ErrorVerifier.Verify(ErrorMessageId.BadUnaryOp, e.Message, "--", "string"))
6860                     return true;
6861             }
6862 
6863             return false;
6864         }
6865     }
6866     //</Code>
6867 }
6868 
6869 
6870 
6871 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate007.operate007
6872 {
6873     using ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.common.common;
6874     // <Title>Bool logical Operator &, | , ^</Title>
6875     // <Description>
6876     // </Description>
6877     // <RelatedBugs></RelatedBugs>
6878     //<Expects Status=success></Expects>
6879     // <Code>
6880 
6881     public class Test
6882     {
6883         [Fact]
DynamicCSharpRunTest()6884         public static void DynamicCSharpRunTest()
6885         {
6886             Assert.Equal(0, MainMethod());
6887         }
6888 
MainMethod()6889         public static int MainMethod()
6890         {
6891             int result = 0;
6892             result += Verify.Eval(Test1);
6893             result += Verify.Eval(Test2);
6894             result += Verify.Eval(Test3);
6895             result += Verify.Eval(Test4);
6896             result += Verify.Eval(Test5);
6897             result += Verify.Eval(Test6);
6898             return result;
6899         }
6900 
Test1()6901         private static bool Test1()
6902         {
6903             bool[] boolValues = new bool[]
6904             {
6905             true, false
6906             }
6907 
6908             ;
6909             foreach (bool a1 in boolValues)
6910             {
6911                 foreach (bool a2 in boolValues)
6912                 {
6913                     dynamic d1 = a1;
6914                     dynamic d2 = a2;
6915                     if ((d1 & d2) != (a1 & a2))
6916                     {
6917                         System.Console.WriteLine("Failed -- bool & bool");
6918                         return false;
6919                     }
6920                 }
6921             }
6922 
6923             return true;
6924         }
6925 
Test2()6926         private static bool Test2()
6927         {
6928             bool?[] boolValues = new bool?[]
6929             {
6930             true, false, null
6931             }
6932 
6933             ;
6934             foreach (bool? a1 in boolValues)
6935             {
6936                 foreach (bool? a2 in boolValues)
6937                 {
6938                     if (a1 == null && a2 == null)
6939                         continue;
6940                     dynamic d1 = a1;
6941                     dynamic d2 = a2;
6942                     if ((d1 & d2) != (a1 & a2))
6943                     {
6944                         System.Console.WriteLine("Failed -- bool? & bool?");
6945                         return false;
6946                     }
6947                 }
6948             }
6949 
6950             return true;
6951         }
6952 
Test3()6953         private static bool Test3()
6954         {
6955             bool[] boolValues = new bool[]
6956             {
6957             true, false
6958             }
6959 
6960             ;
6961             foreach (bool a1 in boolValues)
6962             {
6963                 foreach (bool a2 in boolValues)
6964                 {
6965                     dynamic d1 = a1;
6966                     dynamic d2 = a2;
6967                     if ((d1 | d2) != (a1 | a2))
6968                     {
6969                         System.Console.WriteLine("Failed -- bool | bool");
6970                         return false;
6971                     }
6972                 }
6973             }
6974 
6975             return true;
6976         }
6977 
Test4()6978         private static bool Test4()
6979         {
6980             bool?[] boolValues = new bool?[]
6981             {
6982             true, false, null
6983             }
6984 
6985             ;
6986             foreach (bool? a1 in boolValues)
6987             {
6988                 foreach (bool? a2 in boolValues)
6989                 {
6990                     if (a1 == null && a2 == null)
6991                         continue;
6992                     dynamic d1 = a1;
6993                     dynamic d2 = a2;
6994                     if ((d1 | d2) != (a1 | a2))
6995                     {
6996                         System.Console.WriteLine("Failed -- bool? | bool?");
6997                         return false;
6998                     }
6999                 }
7000             }
7001 
7002             return true;
7003         }
7004 
Test5()7005         private static bool Test5()
7006         {
7007             bool[] boolValues = new bool[]
7008             {
7009             true, false
7010             }
7011 
7012             ;
7013             foreach (bool a1 in boolValues)
7014             {
7015                 foreach (bool a2 in boolValues)
7016                 {
7017                     dynamic d1 = a1;
7018                     dynamic d2 = a2;
7019                     if ((d1 ^ d2) != (a1 ^ a2))
7020                     {
7021                         System.Console.WriteLine("Failed -- bool ^ bool");
7022                         return false;
7023                     }
7024                 }
7025             }
7026 
7027             return true;
7028         }
7029 
Test6()7030         private static bool Test6()
7031         {
7032             bool?[] boolValues = new bool?[]
7033             {
7034             true, false, null
7035             }
7036 
7037             ;
7038             foreach (bool? a1 in boolValues)
7039             {
7040                 foreach (bool? a2 in boolValues)
7041                 {
7042                     if (a1 == null && a2 == null)
7043                         continue;
7044                     dynamic d1 = a1;
7045                     dynamic d2 = a2;
7046                     if ((d1 ^ d2) != (a1 ^ a2))
7047                     {
7048                         System.Console.WriteLine("Failed -- bool? ^ bool?");
7049                         return false;
7050                     }
7051                 }
7052             }
7053 
7054             return true;
7055         }
7056     }
7057     //</Code>
7058 }
7059 
7060 
7061 
7062 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate007a.operate007a
7063 {
7064     using ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.common.common;
7065     // <Title>Bool logical Operator &=, |= , ^=, Compound assignment</Title>
7066     // <Description>
7067     // </Description>
7068     // <RelatedBugs></RelatedBugs>
7069     //<Expects Status=success></Expects>
7070     // <Code>
7071 
7072     public class Test
7073     {
7074         [Fact]
DynamicCSharpRunTest()7075         public static void DynamicCSharpRunTest()
7076         {
7077             Assert.Equal(0, MainMethod());
7078         }
7079 
MainMethod()7080         public static int MainMethod()
7081         {
7082             int result = 0;
7083             result += Verify.Eval(Test1);
7084             result += Verify.Eval(Test2);
7085             result += Verify.Eval(Test3);
7086             result += Verify.Eval(Test4);
7087             result += Verify.Eval(Test5);
7088             result += Verify.Eval(Test6);
7089             return result;
7090         }
7091 
Test1()7092         private static bool Test1()
7093         {
7094             bool[] boolValues = new bool[]
7095             {
7096             true, false
7097             }
7098 
7099             ;
7100             foreach (bool a1 in boolValues)
7101             {
7102                 foreach (bool a2 in boolValues)
7103                 {
7104                     var b11 = a1;
7105                     var b12 = a2;
7106                     var b21 = a1;
7107                     var b22 = a2;
7108                     dynamic d1 = a1;
7109                     dynamic d2 = a2;
7110                     if ((b11 &= d2) != (b21 &= b22))
7111                     {
7112                         System.Console.WriteLine("Failed -- bool &= bool");
7113                         return false;
7114                     }
7115                 }
7116             }
7117 
7118             return true;
7119         }
7120 
Test2()7121         private static bool Test2()
7122         {
7123             int x = 0;
7124             int y = 0;
7125             bool?[] boolValues = new bool?[]
7126             {
7127             true, false, null
7128             }
7129 
7130             ;
7131             foreach (bool? a1 in boolValues)
7132             {
7133                 x++;
7134                 y = 0;
7135                 foreach (bool? a2 in boolValues)
7136                 {
7137                     y++;
7138                     if (a1 == null || a2 == null)
7139                         continue;
7140                     var b11 = a1;
7141                     var b12 = a2;
7142                     var b21 = a1;
7143                     var b22 = a2;
7144                     dynamic d1 = a1;
7145                     dynamic d2 = a2;
7146                     // dynamic not keep bool? type info
7147                     if (b12.HasValue)
7148                     {
7149                         d1 &= b12.Value;
7150                     }
7151                     else if (d1)
7152                     {
7153                         d1 = null;
7154                     }
7155 
7156                     // if (((d1 &= b12) != (b21 &= b22)))
7157                     if (d1 != (b21 &= b22))
7158                     {
7159                         System.Console.WriteLine("Failed -- bool? &= bool?");
7160                         return false;
7161                     }
7162                 }
7163             }
7164 
7165             return true;
7166         }
7167 
Test3()7168         private static bool Test3()
7169         {
7170             bool[] boolValues = new bool[]
7171             {
7172             true, false
7173             }
7174 
7175             ;
7176             foreach (bool a1 in boolValues)
7177             {
7178                 foreach (bool a2 in boolValues)
7179                 {
7180                     var b11 = a1;
7181                     var b12 = a2;
7182                     var b21 = a1;
7183                     var b22 = a2;
7184                     dynamic d1 = a1;
7185                     dynamic d2 = a2;
7186                     if ((d1 |= d2) != (b21 |= b22))
7187                     {
7188                         System.Console.WriteLine("Failed -- bool |= bool");
7189                         return false;
7190                     }
7191                 }
7192             }
7193 
7194             return true;
7195         }
7196 
Test4()7197         private static bool Test4()
7198         {
7199             bool?[] boolValues = new bool?[]
7200             {
7201             true, false, null
7202             }
7203 
7204             ;
7205             foreach (bool? a1 in boolValues)
7206             {
7207                 foreach (bool? a2 in boolValues)
7208                 {
7209                     if (a1 == null && a2 == null)
7210                         continue;
7211                     var b11 = a1;
7212                     var b12 = a2;
7213                     var b21 = a1;
7214                     var b22 = a2;
7215                     dynamic d1 = a1;
7216                     dynamic d2 = a2;
7217                     // dynamic not keep bool? type info - bool OR null obj
7218                     if (null == d1 && null == d2)
7219                     {
7220                         d1 = null;
7221                     }
7222                     else if (null != d1 && null != d2)
7223                     {
7224                         d1 |= d2;
7225                     }
7226                     else
7227                     {
7228                         if (null == d1)
7229                         {
7230                             if (!d2)
7231                                 d1 = null;
7232                             else
7233                                 d1 = d2;
7234                         }
7235 
7236                         if (null == d2)
7237                         {
7238                             if (!d1)
7239                                 d1 = null;
7240                         }
7241                     }
7242 
7243                     //if ((d1 |= d2) != (b21 |= b22))
7244                     if (d1 != (b21 |= b22))
7245                     {
7246                         System.Console.WriteLine("Failed -- bool? |= bool?");
7247                         return false;
7248                     }
7249                 }
7250             }
7251 
7252             return true;
7253         }
7254 
Test5()7255         private static bool Test5()
7256         {
7257             bool[] boolValues = new bool[]
7258             {
7259             true, false
7260             }
7261 
7262             ;
7263             foreach (bool a1 in boolValues)
7264             {
7265                 foreach (bool a2 in boolValues)
7266                 {
7267                     var b11 = a1;
7268                     var b12 = a2;
7269                     var b21 = a1;
7270                     var b22 = a2;
7271                     dynamic d1 = a1;
7272                     dynamic d2 = a2;
7273                     if ((d1 ^= b12) != (b21 ^= b22))
7274                     {
7275                         System.Console.WriteLine("Failed -- bool ^= bool");
7276                         return false;
7277                     }
7278                 }
7279             }
7280 
7281             return true;
7282         }
7283 
Test6()7284         private static bool Test6()
7285         {
7286             bool?[] boolValues = new bool?[]
7287             {
7288             true, false, null
7289             }
7290 
7291             ;
7292             foreach (bool? a1 in boolValues)
7293             {
7294                 foreach (bool? a2 in boolValues)
7295                 {
7296                     if (a1 == null && a2 == null)
7297                         continue;
7298                     var b11 = a1;
7299                     var b12 = a2;
7300                     var b21 = a1;
7301                     var b22 = a2;
7302                     dynamic d1 = a1;
7303                     dynamic d2 = a2;
7304                     if ((b11 ^= d2) != (b21 ^= b22))
7305                     {
7306                         System.Console.WriteLine("Failed -- bool? ^= bool?");
7307                         return false;
7308                     }
7309                 }
7310             }
7311 
7312             return true;
7313         }
7314     }
7315     //</Code>
7316 }
7317 
7318 
7319 
7320 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate007b.operate007b
7321 {
7322     using ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.common.common;
7323     // <Title>Bool logical Operator &=, |= , ^=, Compound assignment</Title>
7324     // <Description>
7325     // dynamic op literals -
7326     // </Description>
7327     // <RelatedBugs></RelatedBugs>
7328     //<Expects Status=success></Expects>
7329     // <Code>
7330 
7331     public class Test
7332     {
7333         [Fact]
DynamicCSharpRunTest()7334         public static void DynamicCSharpRunTest()
7335         {
7336             Assert.Equal(0, MainMethod());
7337         }
7338 
MainMethod()7339         public static int MainMethod()
7340         {
7341             int result = 0;
7342             result += Verify.Eval(Test1);
7343             result += Verify.Eval(Test2);
7344             // dynamic does NOT keep nullable info - either bool or null (obj)
7345             // test3 and test 5 no much value
7346             // result += Verify.Eval(Test3);
7347             result += Verify.Eval(Test4);
7348             // result += Verify.Eval(Test5);
7349             result += Verify.Eval(Test6);
7350             result += Verify.Eval(Test7);
7351             return result;
7352         }
7353 
Test1()7354         private static bool Test1()
7355         {
7356             bool[] boolValues = new bool[]
7357             {
7358             true, false
7359             }
7360 
7361             ;
7362             foreach (bool a1 in boolValues)
7363             {
7364                 var b1 = a1;
7365                 dynamic d1 = a1;
7366                 if ((b1 &= true) != (d1 &= true))
7367                 {
7368                     System.Console.WriteLine("Failed -- bool &= bool");
7369                     return false;
7370                 }
7371             }
7372 
7373             return true;
7374         }
7375 
Test2()7376         private static bool Test2()
7377         {
7378             bool?[] boolValues = new bool?[]
7379             {
7380             true, false, null
7381             }
7382 
7383             ;
7384             foreach (bool? a1 in boolValues)
7385             {
7386                 var b1 = a1;
7387                 dynamic d1 = a1;
7388                 if ((b1 &= false) != (d1 &= false))
7389                 {
7390                     System.Console.WriteLine("Failed -- bool? &= bool?");
7391                     return false;
7392                 }
7393             }
7394 
7395             return true;
7396         }
7397 
Test3()7398         private static bool Test3()
7399         {
7400             bool?[] boolValues = new bool?[]
7401             {
7402             true, false
7403             }
7404 
7405             ;
7406             foreach (bool? a1 in boolValues)
7407             {
7408                 var b1 = a1;
7409                 dynamic d1 = a1;
7410                 if ((b1 &= null) != (d1 &= null))
7411                 {
7412                     System.Console.WriteLine("Failed -- bool? &= null");
7413                     return false;
7414                 }
7415             }
7416 
7417             return true;
7418         }
7419 
Test4()7420         private static bool Test4()
7421         {
7422             bool[] boolValues = new bool[]
7423             {
7424             true, false
7425             }
7426 
7427             ;
7428             foreach (bool a1 in boolValues)
7429             {
7430                 var b1 = a1;
7431                 dynamic d1 = a1;
7432                 if ((b1 |= false) != (d1 |= false))
7433                 {
7434                     System.Console.WriteLine("Failed -- bool |= bool");
7435                     return false;
7436                 }
7437             }
7438 
7439             return true;
7440         }
7441 
Test5()7442         private static bool Test5()
7443         {
7444             bool?[] boolValues = new bool?[]
7445             {
7446             true, false
7447             }
7448 
7449             ;
7450             foreach (bool? a1 in boolValues)
7451             {
7452                 var b1 = a1;
7453                 dynamic d1 = a1;
7454                 if ((b1 |= null) != (d1 |= null))
7455                 {
7456                     System.Console.WriteLine("Failed -- bool? |= null");
7457                     return false;
7458                 }
7459             }
7460 
7461             return true;
7462         }
7463 
Test6()7464         private static bool Test6()
7465         {
7466             bool[] boolValues = new bool[]
7467             {
7468             true, false
7469             }
7470 
7471             ;
7472             foreach (bool a1 in boolValues)
7473             {
7474                 var b1 = a1;
7475                 dynamic d1 = a1;
7476                 if ((b1 ^= true) != (d1 ^= true))
7477                 {
7478                     System.Console.WriteLine("Failed -- bool ^= bool");
7479                     return false;
7480                 }
7481             }
7482 
7483             return true;
7484         }
7485 
Test7()7486         private static bool Test7()
7487         {
7488             bool?[] boolValues = new bool?[]
7489             {
7490             true, false, null
7491             }
7492 
7493             ;
7494             foreach (bool? a1 in boolValues)
7495             {
7496                 var b1 = a1;
7497                 dynamic d1 = a1;
7498                 if ((b1 ^= true) != (d1 ^= true))
7499                 {
7500                     System.Console.WriteLine("Failed -- bool? ^= bool?");
7501                     return false;
7502                 }
7503             }
7504 
7505             return true;
7506         }
7507     }
7508     //</Code>
7509 }
7510 
7511 
7512 
7513 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate008.operate008
7514 {
7515     using ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.common.common;
7516     // <Title>Conditional logical operators ||, &&</Title>
7517     // <Description>
7518     // </Description>
7519     // <RelatedBugs></RelatedBugs>
7520     //<Expects Status=success></Expects>
7521     // <Code>
7522 
7523     public class Test
7524     {
7525         [Fact]
DynamicCSharpRunTest()7526         public static void DynamicCSharpRunTest()
7527         {
7528             Assert.Equal(0, MainMethod());
7529         }
7530 
MainMethod()7531         public static int MainMethod()
7532         {
7533             int result = 0;
7534             result += Verify.Eval(Test1);
7535             result += Verify.Eval(Test2);
7536             result += Verify.Eval(Test3);
7537             result += Verify.Eval(Test4);
7538             return result;
7539         }
7540 
Test1()7541         private static bool Test1()
7542         {
7543             bool[] boolValues = new bool[]
7544             {
7545             true, false
7546             }
7547 
7548             ;
7549             foreach (bool a1 in boolValues)
7550             {
7551                 foreach (bool a2 in boolValues)
7552                 {
7553                     dynamic d1 = a1;
7554                     dynamic d2 = a2;
7555                     if ((d1 || d2) != (a1 || a2))
7556                     {
7557                         System.Console.WriteLine("Failed -- bool & bool");
7558                         return false;
7559                     }
7560                 }
7561             }
7562 
7563             return true;
7564         }
7565 
Test2()7566         private static bool Test2()
7567         {
7568             bool[] boolValues = new bool[]
7569             {
7570             true, false
7571             }
7572 
7573             ;
7574             foreach (bool a1 in boolValues)
7575             {
7576                 foreach (bool a2 in boolValues)
7577                 {
7578                     dynamic d1 = a1;
7579                     bool d2 = a2;
7580                     if ((d1 || d2) != (a1 || a2))
7581                     {
7582                         System.Console.WriteLine("Failed -- bool & bool");
7583                         return false;
7584                     }
7585                 }
7586             }
7587 
7588             return true;
7589         }
7590 
Test3()7591         private static bool Test3()
7592         {
7593             bool[] boolValues = new bool[]
7594             {
7595             true, false
7596             }
7597 
7598             ;
7599             foreach (bool a1 in boolValues)
7600             {
7601                 foreach (bool a2 in boolValues)
7602                 {
7603                     dynamic d1 = a1;
7604                     dynamic d2 = a2;
7605                     if ((d1 && d2) != (a1 && a2))
7606                     {
7607                         System.Console.WriteLine("Failed -- bool | bool");
7608                         return false;
7609                     }
7610                 }
7611             }
7612 
7613             return true;
7614         }
7615 
Test4()7616         private static bool Test4()
7617         {
7618             bool[] boolValues = new bool[]
7619             {
7620             true, false
7621             }
7622 
7623             ;
7624             foreach (bool a1 in boolValues)
7625             {
7626                 foreach (bool a2 in boolValues)
7627                 {
7628                     bool d1 = a1;
7629                     dynamic d2 = a2;
7630                     if ((d1 && d2) != (a1 && a2))
7631                     {
7632                         System.Console.WriteLine("Failed -- bool | bool");
7633                         return false;
7634                     }
7635                 }
7636             }
7637 
7638             return true;
7639         }
7640     }
7641     //</Code>
7642 }
7643 
7644 
7645 
7646 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate008a.operate008a
7647 {
7648     using ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.common.common;
7649     // <Title>Conditional logical operators ||, &&</Title>
7650     // <Description>
7651     // dynamic op literals
7652     // </Description>
7653     // <RelatedBugs></RelatedBugs>
7654     //<Expects Status=success></Expects>
7655     // <Code>
7656 
7657     public class Test
7658     {
7659         [Fact]
DynamicCSharpRunTest()7660         public static void DynamicCSharpRunTest()
7661         {
7662             Assert.Equal(0, MainMethod());
7663         }
7664 
MainMethod()7665         public static int MainMethod()
7666         {
7667             int result = 0;
7668             result += Verify.Eval(Test1);
7669             result += Verify.Eval(Test2);
7670             result += Verify.Eval(Test3);
7671             result += Verify.Eval(Test3a);
7672             result += Verify.Eval(Test4);
7673             result += Verify.Eval(Test4a);
7674             result += Verify.Eval(Test5);
7675             result += Verify.Eval(Test6);
7676             result += Verify.Eval(Test7);
7677             result += Verify.Eval(Test7a);
7678             result += Verify.Eval(Test8);
7679             return result;
7680         }
7681 
Test1()7682         private static bool Test1()
7683         {
7684             bool[] boolValues = new bool[]
7685             {
7686             true, false
7687             }
7688 
7689             ;
7690             foreach (bool a1 in boolValues)
7691             {
7692                 dynamic d1 = a1;
7693                 if ((d1 || true) != (a1 || true))
7694                 {
7695                     System.Console.WriteLine("Failed -- bool || bool");
7696                     return false;
7697                 }
7698             }
7699 
7700             return true;
7701         }
7702 
Test2()7703         private static bool Test2()
7704         {
7705             bool[] boolValues = new bool[]
7706             {
7707             true, false
7708             }
7709 
7710             ;
7711             foreach (bool a1 in boolValues)
7712             {
7713                 dynamic d1 = a1;
7714                 if ((false || d1) != (false || a1))
7715                 {
7716                     System.Console.WriteLine("Failed -- bool || bool");
7717                     return false;
7718                 }
7719             }
7720 
7721             return true;
7722         }
7723 
Test3()7724         private static bool Test3()
7725         {
7726             bool?[] boolValues = new bool?[]
7727             {
7728             true, false
7729             }
7730 
7731             ;
7732             foreach (bool? a1 in boolValues)
7733             {
7734                 dynamic d1 = a1; // should work as bool, dynamic as boxed bool
7735                 if ((false || d1) != (false || a1.Value))
7736                 {
7737                     System.Console.WriteLine("Failed -- bool? || bool?");
7738                     return false;
7739                 }
7740             }
7741 
7742             return true;
7743         }
7744 
Test3a()7745         private static bool Test3a()
7746         {
7747             bool?[] boolValues = new bool?[]
7748             {
7749             null
7750             }
7751 
7752             ;
7753             foreach (bool? a1 in boolValues)
7754             {
7755                 dynamic d1 = a1;
7756                 dynamic d = false || d1; // B#567888
7757                                          // System.Console.WriteLine("Failed -- bool? || bool? Neg");
7758                                          // return false;
7759             }
7760 
7761             return true;
7762         }
7763 
Test4()7764         private static bool Test4()
7765         {
7766             bool?[] boolValues = new bool?[]
7767             {
7768             false
7769             }
7770 
7771             ;
7772             foreach (bool? a1 in boolValues)
7773             {
7774                 dynamic d1 = a1;
7775                 dynamic d = d1 || null; // B#567888
7776                                         // System.Console.WriteLine("Failed -- bool? || null Neg");
7777             }
7778 
7779             return true;
7780         }
7781 
Test4a()7782         private static bool Test4a()
7783         {
7784             bool?[] boolValues = new bool?[]
7785             {
7786             true
7787             }
7788 
7789             ;
7790             foreach (bool? a1 in boolValues)
7791             {
7792                 dynamic d1 = a1;
7793                 if (!(d1 || null))
7794                 {
7795                     System.Console.WriteLine("Failed -- bool? || null");
7796                     return false;
7797                 }
7798             }
7799 
7800             return true;
7801         }
7802 
Test5()7803         private static bool Test5()
7804         {
7805             bool[] boolValues = new bool[]
7806             {
7807             true, false
7808             }
7809 
7810             ;
7811             foreach (bool a1 in boolValues)
7812             {
7813                 dynamic d1 = a1;
7814                 if ((d1 && false) != (a1 && false))
7815                 {
7816                     System.Console.WriteLine("Failed -- bool && bool");
7817                     return false;
7818                 }
7819             }
7820 
7821             return true;
7822         }
7823 
Test6()7824         private static bool Test6()
7825         {
7826             bool[] boolValues = new bool[]
7827             {
7828             true, false
7829             }
7830 
7831             ;
7832             foreach (bool a1 in boolValues)
7833             {
7834                 dynamic d1 = a1;
7835                 if ((true && a1) != (true && d1))
7836                 {
7837                     System.Console.WriteLine("Failed -- bool && bool");
7838                     return false;
7839                 }
7840             }
7841 
7842             return true;
7843         }
7844 
Test7()7845         private static bool Test7()
7846         {
7847             bool?[] boolValues = new bool?[]
7848             {
7849             true, false
7850             }
7851 
7852             ;
7853             foreach (bool? a1 in boolValues)
7854             {
7855                 dynamic d1 = a1; // should work as bool, dynamic as boxed bool
7856                 if ((d1 && true) != (a1.Value && true))
7857                 {
7858                     System.Console.WriteLine("Failed -- bool? && bool?");
7859                     return false;
7860                 }
7861             }
7862 
7863             return true;
7864         }
7865 
Test7a()7866         private static bool Test7a()
7867         {
7868             bool?[] boolValues = new bool?[]
7869             {
7870             null
7871             }
7872 
7873             ;
7874             foreach (bool? a1 in boolValues)
7875             {
7876                 dynamic d1 = a1;
7877                 try
7878                 {
7879                     dynamic d = d1 && true;
7880                     System.Console.WriteLine("Failed -- bool? && bool? Neg");
7881                 }
7882                 catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
7883                 {
7884                     if (ErrorVerifier.Verify(ErrorMessageId.ValueCantBeNull, e.Message, "bool"))
7885                         return true;
7886                 }
7887             }
7888 
7889             return false;
7890         }
7891 
Test8()7892         private static bool Test8()
7893         {
7894             bool?[] boolValues = new bool?[]
7895             {
7896             true
7897             }
7898 
7899             ;
7900             foreach (bool? a1 in boolValues)
7901             {
7902                 dynamic d1 = a1;
7903                 dynamic d = d1 && null; // B#567888
7904                                         // System.Console.WriteLine("Failed -- bool? && null Neg");
7905             }
7906 
7907             return true;
7908         }
7909     }
7910     //</Code>
7911 }
7912 
7913 
7914 
7915 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate009.operate009
7916 {
7917     using ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.common.common;
7918     // <Title>Null coalescing ??</Title>
7919     // <Description>
7920     // </Description>
7921     // <RelatedBugs></RelatedBugs>
7922     //<Expects Status=success></Expects>
7923     // <Code>
7924 
7925     public class Test
7926     {
7927         public enum MyEnum
7928         {
7929             First,
7930             Second,
7931             Third
7932         }
7933 
7934         [Fact]
DynamicCSharpRunTest()7935         public static void DynamicCSharpRunTest()
7936         {
7937             Assert.Equal(0, MainMethod());
7938         }
7939 
MainMethod()7940         public static int MainMethod()
7941         {
7942             int result = 0;
7943             result += Verify.Eval(Test1);
7944             result += Verify.Eval(Test2);
7945             result += Verify.Eval(Test3);
7946             return result;
7947         }
7948 
Test1()7949         private static bool Test1()
7950         {
7951             string[] stringValues = new string[]
7952             {
7953             string.Empty, "ABC", null
7954             }
7955 
7956             ;
7957             foreach (string a1 in stringValues)
7958             {
7959                 foreach (string a2 in stringValues)
7960                 {
7961                     dynamic d1 = a1;
7962                     dynamic d2 = a2;
7963                     if ((d1 ?? d2) != (a1 ?? a2))
7964                     {
7965                         System.Console.WriteLine("Failed -- string ?? string");
7966                         return false;
7967                     }
7968                 }
7969             }
7970 
7971             return true;
7972         }
7973 
Test2()7974         private static bool Test2()
7975         {
7976             int?[] intNValues = new int?[]
7977             {
7978             int.MaxValue, int.MinValue, 0, null
7979             }
7980 
7981             ;
7982             int[] intValues = new int[]
7983             {
7984             int.MaxValue, int.MinValue, 0
7985             }
7986 
7987             ;
7988             foreach (int? a1 in intNValues)
7989             {
7990                 foreach (int a2 in intValues)
7991                 {
7992                     dynamic d1 = a1;
7993                     int d2 = a2;
7994                     if ((d1 ?? d2) != (a1 ?? a2))
7995                     {
7996                         System.Console.WriteLine("Failed -- int? ?? int ");
7997                         return false;
7998                     }
7999                 }
8000             }
8001 
8002             return true;
8003         }
8004 
Test3()8005         private static bool Test3()
8006         {
8007             MyEnum?[] enumNValues = new MyEnum?[]
8008             {
8009             MyEnum.First, MyEnum.Second, MyEnum.Third, null
8010             }
8011 
8012             ;
8013             MyEnum[] enumValues = new MyEnum[]
8014             {
8015             MyEnum.First, MyEnum.Second, MyEnum.Third
8016             }
8017 
8018             ;
8019             foreach (MyEnum? a1 in enumNValues)
8020             {
8021                 foreach (MyEnum a2 in enumValues)
8022                 {
8023                     MyEnum? d1 = a1;
8024                     dynamic d2 = a2;
8025                     if ((d1 ?? d2) != (a1 ?? a2))
8026                     {
8027                         System.Console.WriteLine("Failed -- enum? ?? enum ");
8028                         return false;
8029                     }
8030                 }
8031             }
8032 
8033             return true;
8034         }
8035     }
8036     //</Code>
8037 }
8038 
8039 
8040 
8041 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate009a.operate009a
8042 {
8043     using ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.common.common;
8044     // <Title>Null coalescing ??</Title>
8045     // <Description>
8046     // dynamic op literals
8047     // </Description>
8048     // <RelatedBugs></RelatedBugs>
8049     //<Expects Status=success></Expects>
8050     // <Code>
8051 
8052     public class Test
8053     {
8054         public enum MyEnum
8055         {
8056             First,
8057             Second,
8058             Third
8059         }
8060 
8061         [Fact]
DynamicCSharpRunTest()8062         public static void DynamicCSharpRunTest()
8063         {
8064             Assert.Equal(0, MainMethod());
8065         }
8066 
MainMethod()8067         public static int MainMethod()
8068         {
8069             int result = 0;
8070             result += Verify.Eval(Test1);
8071             result += Verify.Eval(Test1a);
8072             result += Verify.Eval(Test2);
8073             result += Verify.Eval(Test3);
8074             result += Verify.Eval(Test4);
8075             result += Verify.Eval(Test5);
8076             return result;
8077         }
8078 
Test1()8079         private static bool Test1()
8080         {
8081             string[] stringValues = new string[]
8082             {
8083             string.Empty, "ABC", null
8084             }
8085 
8086             ;
8087             foreach (string a1 in stringValues)
8088             {
8089                 dynamic d1 = a1;
8090                 if ((d1 ?? null) != (a1 ?? null))
8091                 {
8092                     System.Console.WriteLine("Failed -- string ?? null");
8093                     return false;
8094                 }
8095             }
8096 
8097             return true;
8098         }
8099 
Test1a()8100         private static bool Test1a()
8101         {
8102             string[] stringValues = new string[]
8103             {
8104             string.Empty, "ABC", null
8105             }
8106 
8107             ;
8108             foreach (string a1 in stringValues)
8109             {
8110                 dynamic d1 = a1;
8111                 if ((d1 ?? string.Empty) != (a1 ?? string.Empty))
8112                 {
8113                     System.Console.WriteLine("Failed -- string ?? string");
8114                     return false;
8115                 }
8116             }
8117 
8118             return true;
8119         }
8120 
Test2()8121         private static bool Test2()
8122         {
8123             string[] stringValues = new string[]
8124             {
8125             string.Empty, "ABC", null
8126             }
8127 
8128             ;
8129             foreach (string a1 in stringValues)
8130             {
8131                 dynamic d1 = a1;
8132                 if ((string.Empty ?? d1) != (string.Empty ?? a1))
8133                 {
8134                     System.Console.WriteLine("Failed -- string ?? string");
8135                     return false;
8136                 }
8137             }
8138 
8139             return true;
8140         }
8141 
Test3()8142         private static bool Test3()
8143         {
8144             string[] stringValues = new string[]
8145             {
8146             string.Empty, "ABC", null
8147             }
8148 
8149             ;
8150             foreach (string a1 in stringValues)
8151             {
8152                 dynamic d1 = 10;
8153                 if ((string.Empty ?? d1) != (string.Empty ?? a1))
8154                 {
8155                     System.Console.WriteLine("Failed -- string ?? string");
8156                     return false;
8157                 }
8158             }
8159 
8160             return true;
8161         }
8162 
Test4()8163         private static bool Test4()
8164         {
8165             int?[] intNValues = new int?[]
8166             {
8167             int.MaxValue, int.MinValue, 0, null
8168             }
8169 
8170             ;
8171             foreach (int? a1 in intNValues)
8172             {
8173                 dynamic d1 = a1;
8174                 if ((d1 ?? 0) != (a1 ?? 0))
8175                 {
8176                     System.Console.WriteLine("Failed -- int? ?? int ");
8177                     return false;
8178                 }
8179             }
8180 
8181             return true;
8182         }
8183 
Test5()8184         private static bool Test5()
8185         {
8186             MyEnum?[] enumNValues = new MyEnum?[]
8187             {
8188             MyEnum.First, MyEnum.Second, MyEnum.Third, null
8189             }
8190 
8191             ;
8192             MyEnum[] enumValues = new MyEnum[]
8193             {
8194             MyEnum.First, MyEnum.Second, MyEnum.Third
8195             }
8196 
8197             ;
8198             foreach (MyEnum? a1 in enumNValues)
8199             {
8200                 dynamic d1 = a1;
8201                 if ((d1 ?? MyEnum.Third) != (a1 ?? MyEnum.Third))
8202                 {
8203                     System.Console.WriteLine("Failed -- enum? ?? enum ");
8204                     return false;
8205                 }
8206             }
8207 
8208             return true;
8209         }
8210     }
8211     //</Code>
8212 }
8213 
8214 
8215 
8216 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate010.operate010
8217 {
8218     using ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.common.common;
8219     // <Title>Conditional operator ? :</Title>
8220     // <Description>
8221     // </Description>
8222     // <RelatedBugs></RelatedBugs>
8223     //<Expects Status=success></Expects>
8224     // <Code>
8225     using System;
8226 
8227     public class Test
8228     {
8229         [Fact]
DynamicCSharpRunTest()8230         public static void DynamicCSharpRunTest()
8231         {
8232             Assert.Equal(0, MainMethod());
8233         }
8234 
MainMethod()8235         public static int MainMethod()
8236         {
8237             int result = 0;
8238             result += Verify.Eval(Test1);
8239             result += Verify.Eval(Test2);
8240             result += Verify.Eval(Test3);
8241             result += Verify.Eval(Test4);
8242             result += Verify.Eval(Test5);
8243             result += Verify.Eval(Test6);
8244             result += Verify.Eval(Test7);
8245             result += Verify.Eval(Test8);
8246             return result;
8247         }
8248 
Test1()8249         private static bool Test1()
8250         {
8251             bool[] boolValues = new bool[]
8252             {
8253             true, false
8254             }
8255 
8256             ;
8257             string[] stringValues = new string[]
8258             {
8259             string.Empty, "ABC", null
8260             }
8261 
8262             ;
8263             foreach (bool a1 in boolValues)
8264             {
8265                 foreach (string a2 in stringValues)
8266                 {
8267                     foreach (string a3 in stringValues)
8268                     {
8269                         dynamic d1 = a1;
8270                         string d2 = a2;
8271                         string d3 = a3;
8272                         if ((d1 ? d2 : d3) != (a1 ? a2 : a3))
8273                         {
8274                             System.Console.WriteLine("Failed -- bool ? string : string");
8275                             return false;
8276                         }
8277                     }
8278                 }
8279             }
8280 
8281             return true;
8282         }
8283 
Test2()8284         private static bool Test2()
8285         {
8286             bool[] boolValues = new bool[]
8287             {
8288             true, false
8289             }
8290 
8291             ;
8292             string[] stringValues = new string[]
8293             {
8294             string.Empty, "ABC", null
8295             }
8296 
8297             ;
8298             foreach (bool a1 in boolValues)
8299             {
8300                 foreach (string a2 in stringValues)
8301                 {
8302                     foreach (string a3 in stringValues)
8303                     {
8304                         bool d1 = a1;
8305                         dynamic d2 = a2;
8306                         string d3 = a3;
8307                         if ((d1 ? d2 : d3) != (a1 ? a2 : a3))
8308                         {
8309                             System.Console.WriteLine("Failed -- bool ? string : string");
8310                             return false;
8311                         }
8312                     }
8313                 }
8314             }
8315 
8316             return true;
8317         }
8318 
Test3()8319         private static bool Test3()
8320         {
8321             bool[] boolValues = new bool[]
8322             {
8323             true, false
8324             }
8325 
8326             ;
8327             string[] stringValues = new string[]
8328             {
8329             string.Empty, "ABC", null
8330             }
8331 
8332             ;
8333             foreach (bool a1 in boolValues)
8334             {
8335                 foreach (string a2 in stringValues)
8336                 {
8337                     foreach (string a3 in stringValues)
8338                     {
8339                         bool d1 = a1;
8340                         string d2 = a2;
8341                         dynamic d3 = a3;
8342                         if ((d1 ? d2 : d3) != (a1 ? a2 : a3))
8343                         {
8344                             System.Console.WriteLine("Failed -- bool ? string : string");
8345                             return false;
8346                         }
8347                     }
8348                 }
8349             }
8350 
8351             return true;
8352         }
8353 
Test4()8354         private static bool Test4()
8355         {
8356             bool[] boolValues = new bool[]
8357             {
8358             true, false
8359             }
8360 
8361             ;
8362             string[] stringValues = new string[]
8363             {
8364             string.Empty, "ABC", null
8365             }
8366 
8367             ;
8368             foreach (bool a1 in boolValues)
8369             {
8370                 foreach (string a2 in stringValues)
8371                 {
8372                     foreach (string a3 in stringValues)
8373                     {
8374                         dynamic d1 = a1;
8375                         dynamic d2 = a2;
8376                         dynamic d3 = a3;
8377                         if ((d1 ? d2 : d3) != (a1 ? a2 : a3))
8378                         {
8379                             System.Console.WriteLine("Failed -- bool ? string : string");
8380                             return false;
8381                         }
8382                     }
8383                 }
8384             }
8385 
8386             return true;
8387         }
8388 
Test5()8389         private static bool Test5()
8390         {
8391             bool[] boolValues = new bool[]
8392             {
8393             true, false
8394             }
8395 
8396             ;
8397             decimal[] longValues = new decimal[]
8398             {
8399             decimal.MaxValue, decimal.MinValue, 0M
8400             }
8401 
8402             ;
8403             foreach (bool a1 in boolValues)
8404             {
8405                 foreach (decimal a2 in longValues)
8406                 {
8407                     foreach (decimal a3 in longValues)
8408                     {
8409                         dynamic d1 = a1;
8410                         decimal d2 = a2;
8411                         decimal d3 = a3;
8412                         if ((d1 ? d2 : d3) != (a1 ? a2 : a3))
8413                         {
8414                             System.Console.WriteLine("Failed -- bool ? decimal : decimal");
8415                             return false;
8416                         }
8417                     }
8418                 }
8419             }
8420 
8421             return true;
8422         }
8423 
Test6()8424         private static bool Test6()
8425         {
8426             bool[] boolValues = new bool[]
8427             {
8428             true, false
8429             }
8430 
8431             ;
8432             long?[] longNValues = new long?[]
8433             {
8434             long.MaxValue, long.MinValue, null
8435             }
8436 
8437             ;
8438             foreach (bool a1 in boolValues)
8439             {
8440                 foreach (long? a2 in longNValues)
8441                 {
8442                     foreach (long? a3 in longNValues)
8443                     {
8444                         bool d1 = a1;
8445                         dynamic d2 = a2;
8446                         long? d3 = a3;
8447                         if ((d1 ? d2 : d3) != (a1 ? a2 : a3))
8448                         {
8449                             System.Console.WriteLine("Failed -- bool ? Nullable<long> : Nullable<long>");
8450                             return false;
8451                         }
8452                     }
8453                 }
8454             }
8455 
8456             return true;
8457         }
8458 
Test7()8459         private static bool Test7()
8460         {
8461             bool[] boolValues = new bool[]
8462             {
8463             true, false
8464             }
8465 
8466             ;
8467             Guid[] guidValues = new Guid[]
8468             {
8469             Guid.NewGuid(), Guid.NewGuid(), default (Guid)}
8470 
8471             ;
8472             foreach (bool a1 in boolValues)
8473             {
8474                 foreach (Guid a2 in guidValues)
8475                 {
8476                     foreach (Guid a3 in guidValues)
8477                     {
8478                         bool d1 = a1;
8479                         Guid d2 = a2;
8480                         dynamic d3 = a3;
8481                         if ((d1 ? d2 : d3) != (a1 ? a2 : a3))
8482                         {
8483                             System.Console.WriteLine("Failed -- bool ? Guid : Guid");
8484                             return false;
8485                         }
8486                     }
8487                 }
8488             }
8489 
8490             return true;
8491         }
8492 
Test8()8493         private static bool Test8()
8494         {
8495             bool[] boolValues = new bool[]
8496             {
8497             true, false
8498             }
8499 
8500             ;
8501             Guid?[] guidNValues = new Guid?[]
8502             {
8503             Guid.NewGuid(), default (Guid), null
8504             }
8505 
8506             ;
8507             foreach (bool a1 in boolValues)
8508             {
8509                 foreach (Guid? a2 in guidNValues)
8510                 {
8511                     foreach (Guid? a3 in guidNValues)
8512                     {
8513                         dynamic d1 = a1;
8514                         dynamic d2 = a2;
8515                         dynamic d3 = a3;
8516                         if ((d1 ? d2 : d3) != (a1 ? a2 : a3))
8517                         {
8518                             System.Console.WriteLine("Failed -- bool ? Nullable<Guid> : Nullable<Guid>");
8519                             return false;
8520                         }
8521                     }
8522                 }
8523             }
8524 
8525             return true;
8526         }
8527     }
8528     //</Code>
8529 }
8530 
8531 
8532 
8533 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate010a.operate010a
8534 {
8535     using ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.common.common;
8536     // <Title>Conditional operator ? :</Title>
8537     // <Description>
8538     // dynamic op literals
8539     // </Description>
8540     // <RelatedBugs></RelatedBugs>
8541     //<Expects Status=success></Expects>
8542     // <Code>
8543     using System;
8544 
8545     public class Test
8546     {
8547         [Fact]
DynamicCSharpRunTest()8548         public static void DynamicCSharpRunTest()
8549         {
8550             Assert.Equal(0, MainMethod());
8551         }
8552 
MainMethod()8553         public static int MainMethod()
8554         {
8555             int result = 0;
8556             result += Verify.Eval(Test1);
8557             result += Verify.Eval(Test2);
8558             result += Verify.Eval(Test3);
8559             result += Verify.Eval(Test3a);
8560             result += Verify.Eval(Test4);
8561             result += Verify.Eval(Test5);
8562             result += Verify.Eval(Test6);
8563             result += Verify.Eval(Test7);
8564             result += Verify.Eval(Test8);
8565             return result;
8566         }
8567 
Test1()8568         private static bool Test1()
8569         {
8570             bool[] boolValues = new bool[]
8571             {
8572             true, false
8573             }
8574 
8575             ;
8576             string[] stringValues = new string[]
8577             {
8578             string.Empty, "ABC", null
8579             }
8580 
8581             ;
8582             foreach (bool a1 in boolValues)
8583             {
8584                 foreach (string a3 in stringValues)
8585                 {
8586                     dynamic d1 = a1;
8587                     string d3 = a3;
8588                     if ((d1 ? null : d3) != (a1 ? null : a3))
8589                     {
8590                         System.Console.WriteLine("Failed -- bool ? string : string");
8591                         return false;
8592                     }
8593                 }
8594             }
8595 
8596             return true;
8597         }
8598 
Test2()8599         private static bool Test2()
8600         {
8601             bool[] boolValues = new bool[]
8602             {
8603             true, false
8604             }
8605 
8606             ;
8607             string[] stringValues = new string[]
8608             {
8609             string.Empty, "ABC", null
8610             }
8611 
8612             ;
8613             foreach (bool a1 in boolValues)
8614             {
8615                 foreach (string a2 in stringValues)
8616                 {
8617                     bool d1 = a1;
8618                     dynamic d2 = a2;
8619                     if ((d1 ? d2 : string.Empty) != (a1 ? a2 : string.Empty))
8620                     {
8621                         System.Console.WriteLine("Failed -- bool ? string : string");
8622                         return false;
8623                     }
8624                 }
8625             }
8626 
8627             return true;
8628         }
8629 
Test3()8630         private static bool Test3()
8631         {
8632             bool[] boolValues = new bool[]
8633             {
8634             true, false
8635             }
8636 
8637             ;
8638             string[] stringValues = new string[]
8639             {
8640             string.Empty, "ABC", null
8641             }
8642 
8643             ;
8644             foreach (string a2 in stringValues)
8645             {
8646                 foreach (string a3 in stringValues)
8647                 {
8648                     string d2 = a2;
8649                     dynamic d3 = a3;
8650                     if ((false ? d2 : d3) != (false ? a2 : a3))
8651                     {
8652                         System.Console.WriteLine("Failed -- bool ? string : string");
8653                         return false;
8654                     }
8655                 }
8656             }
8657 
8658             return true;
8659         }
8660 
Test3a()8661         private static bool Test3a()
8662         {
8663             bool[] boolValues = new bool[]
8664             {
8665             true, false
8666             }
8667 
8668             ;
8669             string[] stringValues = new string[]
8670             {
8671             string.Empty, "ABC", null
8672             }
8673 
8674             ;
8675             foreach (string a2 in stringValues)
8676             {
8677                 foreach (string a3 in stringValues)
8678                 {
8679                     bool d1 = true;
8680                     string d2 = a2;
8681                     dynamic d3 = 100;
8682                     if ((d1 ? "ABC" : d3) != (d1 ? "ABC" : a3))
8683                     {
8684                         System.Console.WriteLine("Failed -- bool ? string : string");
8685                         return false;
8686                     }
8687                 }
8688             }
8689 
8690             return true;
8691         }
8692 
Test4()8693         private static bool Test4()
8694         {
8695             bool[] boolValues = new bool[]
8696             {
8697             true, false
8698             }
8699 
8700             ;
8701             string[] stringValues = new string[]
8702             {
8703             string.Empty, "ABC", null
8704             }
8705 
8706             ;
8707             foreach (bool a1 in boolValues)
8708             {
8709                 foreach (string a3 in stringValues)
8710                 {
8711                     dynamic d1 = a1;
8712                     dynamic d3 = a3;
8713                     if ((d1 ? "ABCD" : d3) != (a1 ? "ABCD" : a3))
8714                     {
8715                         System.Console.WriteLine("Failed -- bool ? string : string");
8716                         return false;
8717                     }
8718                 }
8719             }
8720 
8721             return true;
8722         }
8723 
Test5()8724         private static bool Test5()
8725         {
8726             bool[] boolValues = new bool[]
8727             {
8728             true, false
8729             }
8730 
8731             ;
8732             decimal[] longValues = new decimal[]
8733             {
8734             decimal.MaxValue, decimal.MinValue, 0M
8735             }
8736 
8737             ;
8738             foreach (bool a1 in boolValues)
8739             {
8740                 foreach (decimal a2 in longValues)
8741                 {
8742                     dynamic d1 = a1;
8743                     decimal d2 = a2;
8744                     if ((d1 ? d2 : 10.01M) != (a1 ? a2 : 10.01M))
8745                     {
8746                         System.Console.WriteLine("Failed -- bool ? decimal : decimal");
8747                         return false;
8748                     }
8749                 }
8750             }
8751 
8752             return true;
8753         }
8754 
Test6()8755         private static bool Test6()
8756         {
8757             bool[] boolValues = new bool[]
8758             {
8759             true, false
8760             }
8761 
8762             ;
8763             long?[] longNValues = new long?[]
8764             {
8765             long.MaxValue, long.MinValue, null
8766             }
8767 
8768             ;
8769             foreach (bool a1 in boolValues)
8770             {
8771                 foreach (long? a2 in longNValues)
8772                 {
8773                     bool d1 = a1;
8774                     dynamic d2 = a2;
8775                     if ((d1 ? d2 : 10L) != (a1 ? a2 : 10L))
8776                     {
8777                         System.Console.WriteLine("Failed -- bool ? Nullable<long> : Nullable<long>");
8778                         return false;
8779                     }
8780                 }
8781             }
8782 
8783             return true;
8784         }
8785 
Test7()8786         private static bool Test7()
8787         {
8788             bool[] boolValues = new bool[]
8789             {
8790             true, false
8791             }
8792 
8793             ;
8794             Guid[] guidValues = new Guid[]
8795             {
8796             Guid.NewGuid(), Guid.NewGuid(), default (Guid)}
8797 
8798             ;
8799             foreach (bool a1 in boolValues)
8800             {
8801                 foreach (Guid a3 in guidValues)
8802                 {
8803                     bool d1 = a1;
8804                     dynamic d3 = a3;
8805                     if ((d1 ? default(Guid) : d3) != (a1 ? default(Guid) : a3))
8806                     {
8807                         System.Console.WriteLine("Failed -- bool ? Guid : Guid");
8808                         return false;
8809                     }
8810                 }
8811             }
8812 
8813             return true;
8814         }
8815 
Test8()8816         private static bool Test8()
8817         {
8818             bool[] boolValues = new bool[]
8819             {
8820             true, false
8821             }
8822 
8823             ;
8824             Guid?[] guidNValues = new Guid?[]
8825             {
8826             Guid.NewGuid(), default (Guid), null
8827             }
8828 
8829             ;
8830             foreach (bool a1 in boolValues)
8831             {
8832                 foreach (Guid? a2 in guidNValues)
8833                 {
8834                     dynamic d1 = a1;
8835                     dynamic d2 = a2;
8836                     if ((d1 ? d2 : null) != (a1 ? a2 : null))
8837                     {
8838                         System.Console.WriteLine("Failed -- bool ? Nullable<Guid> : Nullable<Guid>");
8839                         return false;
8840                     }
8841                 }
8842             }
8843 
8844             return true;
8845         }
8846     }
8847     //</Code>
8848 }
8849 
8850 
8851 
8852 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate011.operate011
8853 {
8854     using ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.common.common;
8855     // <Title>Equality operator</Title>
8856     // <Description>
8857     // </Description>
8858     // <RelatedBugs></RelatedBugs>
8859     //<Expects Status=success></Expects>
8860     // <Code>
8861     using System;
8862 
8863     public class Test
8864     {
8865         public enum MyEnum
8866         {
8867             First,
8868             Second,
8869             Third
8870         }
8871 
8872         [Fact]
DynamicCSharpRunTest()8873         public static void DynamicCSharpRunTest()
8874         {
8875             Assert.Equal(0, MainMethod());
8876         }
8877 
MainMethod()8878         public static int MainMethod()
8879         {
8880             int result = 0;
8881             result += Verify.Eval(Test1);
8882             result += Verify.Eval(Test2);
8883             result += Verify.Eval(Test3);
8884             result += Verify.Eval(Test4);
8885             result += Verify.Eval(Test5);
8886             result += Verify.Eval(Test6);
8887             result += Verify.Eval(Test7);
8888             result += Verify.Eval(Test8);
8889             return result;
8890         }
8891 
Test1()8892         private static bool Test1()
8893         {
8894             string[] stringValues = new string[]
8895             {
8896             string.Empty, "ABC", null
8897             }
8898 
8899             ;
8900             foreach (string a1 in stringValues)
8901             {
8902                 dynamic d1 = a1;
8903                 if (d1 != a1)
8904                 {
8905                     System.Console.WriteLine("Failed -- string Equality1");
8906                     return false;
8907                 }
8908             }
8909 
8910             return true;
8911         }
8912 
Test2()8913         private static bool Test2()
8914         {
8915             int?[] intNValues = new int?[]
8916             {
8917             int.MaxValue, int.MinValue, 0, null
8918             }
8919 
8920             ;
8921             foreach (int? a1 in intNValues)
8922             {
8923                 dynamic d1 = a1;
8924                 dynamic d2 = a1;
8925                 if (d1 != d2)
8926                 {
8927                     System.Console.WriteLine("Failed -- Nullable<int> Equality2");
8928                     return false;
8929                 }
8930             }
8931 
8932             return true;
8933         }
8934 
Test3()8935         private static bool Test3()
8936         {
8937             Guid[] guidValues = new Guid[]
8938             {
8939             Guid.NewGuid(), Guid.NewGuid(), default (Guid)}
8940 
8941             ;
8942             for (int i = 0; i < guidValues.Length; i++)
8943             {
8944                 for (int j = 0; j < guidValues.Length; j++)
8945                 {
8946                     if (i != j)
8947                     {
8948                         dynamic d1 = guidValues[i];
8949                         if (d1 == guidValues[j])
8950                         {
8951                             System.Console.WriteLine("Failed -- Guid Equality3");
8952                             return false;
8953                         }
8954                     }
8955                 }
8956             }
8957 
8958             return true;
8959         }
8960 
Test4()8961         private static bool Test4()
8962         {
8963             decimal[] decimalValues = new decimal[]
8964             {
8965             decimal.MaxValue, decimal.MinusOne, 0M
8966             }
8967 
8968             ;
8969             for (int i = 0; i < decimalValues.Length; i++)
8970             {
8971                 for (int j = 0; j < decimalValues.Length; j++)
8972                 {
8973                     if (i != j)
8974                     {
8975                         dynamic d1 = decimalValues[i];
8976                         if (decimalValues[j] == d1)
8977                         {
8978                             System.Console.WriteLine("Failed -- decimal Equality4");
8979                             return false;
8980                         }
8981                     }
8982                 }
8983             }
8984 
8985             return true;
8986         }
8987 
Test5()8988         private static bool Test5()
8989         {
8990             DateTime[] datetimeValues = new DateTime[]
8991             {
8992             DateTime.Now.AddHours(10.00), DateTime.Now.AddHours(5.00), DateTime.Now
8993             }
8994 
8995             ;
8996             foreach (DateTime a1 in datetimeValues)
8997             {
8998                 dynamic d1 = a1;
8999                 if (d1 != a1)
9000                 {
9001                     System.Console.WriteLine("Failed -- DateTime Equality5");
9002                     return false;
9003                 }
9004             }
9005 
9006             return true;
9007         }
9008 
Test6()9009         private static bool Test6()
9010         {
9011             long[] longValues = new long[]
9012             {
9013             long.MaxValue, long.MinValue, 0
9014             }
9015 
9016             ;
9017             foreach (long a1 in longValues)
9018             {
9019                 dynamic d1 = a1;
9020                 dynamic d2 = a1;
9021                 if (d1 != d2)
9022                 {
9023                     System.Console.WriteLine("Failed -- long Equality6");
9024                     return false;
9025                 }
9026             }
9027 
9028             return true;
9029         }
9030 
Test7()9031         private static bool Test7()
9032         {
9033             MyEnum[] enumValues = new MyEnum[]
9034             {
9035             MyEnum.First, MyEnum.Second, MyEnum.Third
9036             }
9037 
9038             ;
9039             for (int i = 0; i < enumValues.Length; i++)
9040             {
9041                 for (int j = 0; j < enumValues.Length; j++)
9042                 {
9043                     if (i != j)
9044                     {
9045                         dynamic d1 = enumValues[i];
9046                         if (d1 == enumValues[j])
9047                         {
9048                             System.Console.WriteLine("Failed -- enum Equality7");
9049                             return false;
9050                         }
9051                     }
9052                 }
9053             }
9054 
9055             return true;
9056         }
9057 
Test8()9058         private static bool Test8()
9059         {
9060             MyEnum?[] enumValues = new MyEnum?[]
9061             {
9062             MyEnum.First, MyEnum.Second, MyEnum.Third, null
9063             }
9064 
9065             ;
9066             for (int i = 0; i < enumValues.Length; i++)
9067             {
9068                 for (int j = 0; j < enumValues.Length; j++)
9069                 {
9070                     if (i != j)
9071                     {
9072                         dynamic d1 = enumValues[i];
9073                         if (enumValues[j] == d1)
9074                         {
9075                             System.Console.WriteLine("Failed -- Nullable<enum> Equality8");
9076                             return false;
9077                         }
9078                     }
9079                 }
9080             }
9081 
9082             return true;
9083         }
9084     }
9085     //</Code>
9086 }
9087 
9088 
9089 
9090 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate011b.operate011b
9091 {
9092     using ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.common.common;
9093     // <Title>Equality operator when one operand is literal null</Title>
9094     // <Description>
9095     // </Description>
9096     // <RelatedBugs></RelatedBugs>
9097     // <Expects Status=success></Expects>
9098     // <Code>
9099     using Microsoft.CSharp.RuntimeBinder;
9100 
9101     #region "Type definition"
9102     public enum MyEnum
9103     {
9104         First,
9105     }
9106 
9107     public struct MyStruct
9108     {
9109     }
9110 
9111     public struct MyStruct2
9112     {
9113         private int _f1;
MyStruct2ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate011b.operate011b.MyStruct29114         public MyStruct2(int p1)
9115         {
9116             _f1 = p1;
9117         }
9118 
operator ==ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate011b.operate011b.MyStruct29119         public static bool operator ==(MyStruct2 lf, MyStruct2 rh)
9120         {
9121             return lf._f1 == rh._f1;
9122         }
9123 
operator !=ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate011b.operate011b.MyStruct29124         public static bool operator !=(MyStruct2 lf, MyStruct2 rh)
9125         {
9126             return lf._f1 != rh._f1;
9127         }
9128 
EqualsManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate011b.operate011b.MyStruct29129         public override bool Equals(object obj)
9130         {
9131             return base.Equals(obj);
9132         }
9133 
GetHashCodeManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate011b.operate011b.MyStruct29134         public override int GetHashCode()
9135         {
9136             return base.GetHashCode();
9137         }
9138     }
9139     #endregion
9140     public class Test
9141     {
9142         [Fact]
DynamicCSharpRunTest()9143         public static void DynamicCSharpRunTest()
9144         {
9145             Assert.Equal(0, MainMethod());
9146         }
9147 
MainMethod()9148         public static int MainMethod()
9149         {
9150             int result = 0;
9151             // int type
9152             result += Verify.Eval(Test1);
9153             result += Verify.Eval(Test2);
9154             result += Verify.Eval(Test3);
9155             result += Verify.Eval(Test4);
9156             // argument
9157             result += Verify.Eval(Test5);
9158             // enum type
9159             result += Verify.Eval(Test11);
9160             result += Verify.Eval(Test12);
9161             result += Verify.Eval(Test13);
9162             result += Verify.Eval(Test14);
9163             // struct type without user defined equality operators
9164             result += Verify.Eval(Test21);
9165             result += Verify.Eval(Test22);
9166             result += Verify.Eval(Test23);
9167             result += Verify.Eval(Test24);
9168             // type parameter
9169             result += Verify.Eval(Test31<long>);
9170             result += Verify.Eval(Test32<long>);
9171             result += Verify.Eval(Test33<long>);
9172             result += Verify.Eval(Test34<long>);
9173             // struct with user defined equality operators
9174             result += Verify.Eval(Test41);
9175             result += Verify.Eval(Test42);
9176             result += Verify.Eval(Test43);
9177             result += Verify.Eval(Test44);
9178             // nullable type without user defined equality operators
9179             result += Verify.Eval(Test51);
9180             result += Verify.Eval(Test52);
9181             result += Verify.Eval(Test53);
9182             result += Verify.Eval(Test54);
9183             result += Verify.Eval(Test55);
9184             // nullable type with user defined equality operators
9185             result += Verify.Eval(Test61);
9186             result += Verify.Eval(Test62);
9187             result += Verify.Eval(Test63);
9188             result += Verify.Eval(Test64);
9189             return result;
9190         }
9191 
9192         #region "int type"
Test1()9193         private static bool Test1()
9194         {
9195             dynamic d = 10;
9196             if (d == null)
9197                 return false;
9198             return true;
9199         }
9200 
Test2()9201         private static bool Test2()
9202         {
9203             dynamic d = 10;
9204             if (d != null)
9205                 return true;
9206             return false;
9207         }
9208 
Test3()9209         private static bool Test3()
9210         {
9211             dynamic d = 10;
9212             if (null == d)
9213                 return false;
9214             return true;
9215         }
9216 
Test4()9217         private static bool Test4()
9218         {
9219             dynamic d = 10;
9220             if (null != d)
9221                 return true;
9222             return false;
9223         }
9224 
9225         #endregion
M5(dynamic p1)9226         public bool M5(dynamic p1)
9227         {
9228             if (p1 == null)
9229                 return false;
9230             else
9231                 return true;
9232         }
9233 
Test5()9234         private static bool Test5()
9235         {
9236             dynamic obj = new Test();
9237             return obj.M5(10);
9238         }
9239 
9240         #region "Enum type"
Test11()9241         private static bool Test11()
9242         {
9243             dynamic d = MyEnum.First;
9244             if (d == null)
9245                 return false;
9246             return true;
9247         }
9248 
Test12()9249         private static bool Test12()
9250         {
9251             dynamic d = MyEnum.First;
9252             if (d != null)
9253                 return true;
9254             return false;
9255         }
9256 
Test13()9257         private static bool Test13()
9258         {
9259             dynamic d = MyEnum.First;
9260             if (null == d)
9261                 return false;
9262             return true;
9263         }
9264 
Test14()9265         private static bool Test14()
9266         {
9267             dynamic d = MyEnum.First;
9268             if (null != d)
9269                 return true;
9270             return false;
9271         }
9272 
9273         #endregion
9274         #region "struct type without user defined equality operators. "
9275 
Test21()9276         private static bool Test21()
9277         {
9278             dynamic d = new MyStruct();
9279             try
9280             {
9281                 if (d == null)
9282                     return false;
9283             }
9284             catch (RuntimeBinderException e)
9285             {
9286                 if (ErrorVerifier.Verify(ErrorMessageId.BadBinaryOps, e.Message, "==", "MyStruct", ErrorVerifier.GetErrorElement(ErrorElementId.NULL)))
9287                     return true;
9288             }
9289 
9290             return false;
9291         }
9292 
Test22()9293         private static bool Test22()
9294         {
9295             dynamic d = new MyStruct();
9296             try
9297             {
9298                 if (d != null)
9299                     return false;
9300             }
9301             catch (RuntimeBinderException e)
9302             {
9303                 if (ErrorVerifier.Verify(ErrorMessageId.BadBinaryOps, e.Message, "!=", "MyStruct", ErrorVerifier.GetErrorElement(ErrorElementId.NULL)))
9304                     return true;
9305             }
9306 
9307             return false;
9308         }
9309 
Test23()9310         private static bool Test23()
9311         {
9312             dynamic d = new MyStruct();
9313             try
9314             {
9315                 if (null == d)
9316                     return false;
9317             }
9318             catch (RuntimeBinderException e)
9319             {
9320                 if (ErrorVerifier.Verify(ErrorMessageId.BadBinaryOps, e.Message, "==", ErrorVerifier.GetErrorElement(ErrorElementId.NULL), "MyStruct"))
9321                     return true;
9322             }
9323 
9324             return false;
9325         }
9326 
Test24()9327         private static bool Test24()
9328         {
9329             dynamic d = new MyStruct();
9330             try
9331             {
9332                 if (null != d)
9333                     return false;
9334             }
9335             catch (RuntimeBinderException e)
9336             {
9337                 if (ErrorVerifier.Verify(ErrorMessageId.BadBinaryOps, e.Message, "!=", ErrorVerifier.GetErrorElement(ErrorElementId.NULL), "MyStruct"))
9338                     return true;
9339             }
9340 
9341             return false;
9342         }
9343 
9344         #endregion
9345         #region "Type parameter"
9346         private static bool Test31<T>() where T : struct
9347         {
9348             dynamic d = default(T);
9349             if (d == null)
9350                 return false;
9351             return true;
9352         }
9353 
9354         private static bool Test32<T>() where T : struct
9355         {
9356             dynamic d = default(T);
9357             if (d != null)
9358                 return true;
9359             return false;
9360         }
9361 
9362         private static bool Test33<T>() where T : struct
9363         {
9364             dynamic d = default(T);
9365             if (null == d)
9366                 return false;
9367             return true;
9368         }
9369 
9370         private static bool Test34<T>() where T : struct
9371         {
9372             dynamic d = default(T);
9373             if (null != d)
9374                 return true;
9375             return false;
9376         }
9377 
9378         #endregion
9379         #region "Struct type with user defined equality operators"
9380 
Test41()9381         private static bool Test41()
9382         {
9383             dynamic d = new MyStruct2(1);
9384             if (d == null)
9385                 return false;
9386             return true;
9387         }
9388 
Test42()9389         private static bool Test42()
9390         {
9391             dynamic d = new MyStruct2(1);
9392             if (d != null)
9393                 return true;
9394             return false;
9395         }
9396 
Test43()9397         private static bool Test43()
9398         {
9399             dynamic d = new MyStruct2(1);
9400             if (null == d)
9401                 return false;
9402             return true;
9403         }
9404 
Test44()9405         private static bool Test44()
9406         {
9407             dynamic d = new MyStruct2(1);
9408             if (null != d)
9409                 return true;
9410             return false;
9411         }
9412 
9413         #endregion
9414         #region "Nullable struct without user-defined equality operators"
Test51()9415         private static bool Test51()
9416         {
9417             MyStruct? ns = new MyStruct();
9418             dynamic d = ns;
9419             try
9420             {
9421                 if (d == null)
9422                     return false;
9423             }
9424             catch (RuntimeBinderException e)
9425             {
9426                 if (ErrorVerifier.Verify(ErrorMessageId.BadBinaryOps, e.Message, "==", "MyStruct", ErrorVerifier.GetErrorElement(ErrorElementId.NULL)))
9427                     return true;
9428             }
9429 
9430             return false;
9431         }
9432 
Test52()9433         private static bool Test52()
9434         {
9435             MyStruct? ns = new MyStruct();
9436             dynamic d = ns;
9437             try
9438             {
9439                 if (d != null)
9440                     return false;
9441             }
9442             catch (RuntimeBinderException e)
9443             {
9444                 if (ErrorVerifier.Verify(ErrorMessageId.BadBinaryOps, e.Message, "!=", "MyStruct", ErrorVerifier.GetErrorElement(ErrorElementId.NULL)))
9445                     return true;
9446             }
9447 
9448             return false;
9449         }
9450 
Test53()9451         private static bool Test53()
9452         {
9453             MyStruct? ns = new MyStruct();
9454             dynamic d = ns;
9455             try
9456             {
9457                 if (null == d)
9458                     return false;
9459             }
9460             catch (RuntimeBinderException e)
9461             {
9462                 if (ErrorVerifier.Verify(ErrorMessageId.BadBinaryOps, e.Message, "==", ErrorVerifier.GetErrorElement(ErrorElementId.NULL), "MyStruct"))
9463                     return true;
9464             }
9465 
9466             return false;
9467         }
9468 
Test54()9469         private static bool Test54()
9470         {
9471             MyStruct? ns = new MyStruct();
9472             dynamic d = ns;
9473             try
9474             {
9475                 if (null != d)
9476                     return false;
9477             }
9478             catch (RuntimeBinderException e)
9479             {
9480                 if (ErrorVerifier.Verify(ErrorMessageId.BadBinaryOps, e.Message, "!=", ErrorVerifier.GetErrorElement(ErrorElementId.NULL), "MyStruct"))
9481                     return true;
9482             }
9483 
9484             return false;
9485         }
9486 
Test55()9487         private static bool Test55()
9488         {
9489             MyStruct? ns = null;
9490             dynamic d = ns;
9491             if (d == null)
9492                 return true;
9493             return false;
9494         }
9495 
9496         #endregion
9497         #region "Nullable type with user defined equality operators"
9498 
Test61()9499         private static bool Test61()
9500         {
9501             MyStruct2? ns = new MyStruct2(1);
9502             dynamic d = ns;
9503             if (d == null)
9504                 return false;
9505             return true;
9506         }
9507 
Test62()9508         private static bool Test62()
9509         {
9510             MyStruct2? ns = new MyStruct2(1);
9511             dynamic d = ns;
9512             if (d != null)
9513                 return true;
9514             return false;
9515         }
9516 
Test63()9517         private static bool Test63()
9518         {
9519             MyStruct2? ns = new MyStruct2(1);
9520             dynamic d = ns;
9521             if (null == d)
9522                 return false;
9523             return true;
9524         }
9525 
Test64()9526         private static bool Test64()
9527         {
9528             MyStruct2? ns = new MyStruct2(1);
9529             dynamic d = ns;
9530             if (null != d)
9531                 return true;
9532             return false;
9533         }
9534         #endregion
9535     }
9536     //</Code>
9537 }
9538 
9539 
9540 
9541 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate012.operate012
9542 {
9543     using ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.common.common;
9544     // <Title>Relational operator</Title>
9545     // <Description>
9546     // </Description>
9547     // <RelatedBugs></RelatedBugs>
9548     //<Expects Status=success></Expects>
9549     // <Code>
9550 
9551     public class Test
9552     {
9553         public enum MyEnum
9554         {
9555             First,
9556             Second,
9557             Third
9558         }
9559 
9560         [Fact]
DynamicCSharpRunTest()9561         public static void DynamicCSharpRunTest()
9562         {
9563             Assert.Equal(0, MainMethod());
9564         }
9565 
MainMethod()9566         public static int MainMethod()
9567         {
9568             int result = 0;
9569             result += Verify.Eval(Test1);
9570             result += Verify.Eval(Test2);
9571             result += Verify.Eval(Test3);
9572             result += Verify.Eval(Test4);
9573             return result;
9574         }
9575 
Test1()9576         private static bool Test1()
9577         {
9578             long[] longValues = new long[]
9579             {
9580             long.MinValue, long.MinValue, 0
9581             }
9582 
9583             ;
9584             foreach (long a1 in longValues)
9585             {
9586                 foreach (long a2 in longValues)
9587                 {
9588                     dynamic d1 = a1;
9589                     if ((d1 < a2) != (a1 < a2))
9590                     {
9591                         System.Console.WriteLine("Failed -- long < long");
9592                         return false;
9593                     }
9594                 }
9595             }
9596 
9597             return true;
9598         }
9599 
Test2()9600         private static bool Test2()
9601         {
9602             decimal?[] decimalNValues = new decimal?[]
9603             {
9604             decimal.MaxValue, int.MinValue, default (decimal), null
9605             }
9606 
9607             ;
9608             foreach (decimal? a1 in decimalNValues)
9609             {
9610                 foreach (decimal? a2 in decimalNValues)
9611                 {
9612                     dynamic d2 = a2;
9613                     if ((a1 > d2) != (a1 > a2))
9614                     {
9615                         System.Console.WriteLine("Failed -- decimal? > decimal?");
9616                         return false;
9617                     }
9618                 }
9619             }
9620 
9621             return true;
9622         }
9623 
Test3()9624         private static bool Test3()
9625         {
9626             char?[] charNValues = new char?[]
9627             {
9628             'a', 'b', default (char), null
9629             }
9630 
9631             ;
9632             foreach (char? a1 in charNValues)
9633             {
9634                 foreach (char? a2 in charNValues)
9635                 {
9636                     dynamic d1 = a1;
9637                     dynamic d2 = a2;
9638                     if ((d1 <= d2) != (a1 <= a2))
9639                     {
9640                         System.Console.WriteLine("Failed -- char? <= char?");
9641                         return false;
9642                     }
9643                 }
9644             }
9645 
9646             return true;
9647         }
9648 
Test4()9649         private static bool Test4()
9650         {
9651             MyEnum[] enumValues = new MyEnum[]
9652             {
9653             MyEnum.First, MyEnum.Second, MyEnum.Third
9654             }
9655 
9656             ;
9657             foreach (MyEnum a1 in enumValues)
9658             {
9659                 foreach (MyEnum a2 in enumValues)
9660                 {
9661                     dynamic d2 = a2;
9662                     if ((a1 >= d2) != (a1 >= a2))
9663                     {
9664                         System.Console.WriteLine("Failed -- enum >= enum");
9665                         return false;
9666                     }
9667                 }
9668             }
9669 
9670             return true;
9671         }
9672     }
9673     //</Code>
9674 }
9675 
9676 
9677 
9678 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate012a.operate012a
9679 {
9680     using ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.common.common;
9681     // <Title>Relational operator</Title>
9682     // <Description>
9683     // dynamic op literals
9684     // </Description>
9685     // <RelatedBugs></RelatedBugs>
9686     //<Expects Status=success></Expects>
9687     // <Code>
9688     //<Expects Status=warning>\(69,33\).*CS0464</Expects>
9689 
9690     public class Test
9691     {
9692         public enum MyEnum
9693         {
9694             First,
9695             Second,
9696             Third
9697         }
9698 
9699         [Fact]
DynamicCSharpRunTest()9700         public static void DynamicCSharpRunTest()
9701         {
9702             Assert.Equal(0, MainMethod());
9703         }
9704 
MainMethod()9705         public static int MainMethod()
9706         {
9707             int result = 0;
9708             result += Verify.Eval(Test1);
9709             result += Verify.Eval(Test2);
9710             result += Verify.Eval(Test3);
9711             result += Verify.Eval(Test4);
9712             return result;
9713         }
9714 
Test1()9715         private static bool Test1()
9716         {
9717             long[] longValues = new long[]
9718             {
9719             long.MinValue, long.MinValue, 0
9720             }
9721 
9722             ;
9723             foreach (long a1 in longValues)
9724             {
9725                 dynamic d1 = a1;
9726                 if ((d1 < 10) != (a1 < 10))
9727                 {
9728                     System.Console.WriteLine("Failed -- long < long");
9729                     return false;
9730                 }
9731             }
9732 
9733             return true;
9734         }
9735 
Test2()9736         private static bool Test2()
9737         {
9738             decimal?[] decimalNValues = new decimal?[]
9739             {
9740             decimal.MaxValue, int.MinValue, default (decimal), null
9741             }
9742 
9743             ;
9744             foreach (decimal? a2 in decimalNValues)
9745             {
9746                 dynamic d2 = a2;
9747                 if ((10M > d2) != (10M > a2))
9748                 {
9749                     System.Console.WriteLine("Failed -- decimal? > decimal?");
9750                     return false;
9751                 }
9752             }
9753 
9754             return true;
9755         }
9756 
Test2a()9757         private static bool Test2a()
9758         {
9759             decimal?[] decimalNValues = new decimal?[]
9760             {
9761             decimal.MaxValue, int.MinValue, default (decimal), null
9762             }
9763 
9764             ;
9765             foreach (decimal? a2 in decimalNValues)
9766             {
9767                 dynamic d2 = a2;
9768                 if ((d2 > null) != (a2 > null))
9769                 {
9770                     System.Console.WriteLine("Failed -- decimal? > decimal?");
9771                     return false;
9772                 }
9773             }
9774 
9775             return true;
9776         }
9777 
Test3()9778         private static bool Test3()
9779         {
9780             char?[] charNValues = new char?[]
9781             {
9782             'a', 'b', default (char), null
9783             }
9784 
9785             ;
9786             foreach (char? a2 in charNValues)
9787             {
9788                 dynamic d2 = a2;
9789                 if ((default(char) <= d2) != (default(char) <= a2))
9790                 {
9791                     System.Console.WriteLine("Failed -- char? <= char?");
9792                     return false;
9793                 }
9794             }
9795 
9796             return true;
9797         }
9798 
Test4()9799         private static bool Test4()
9800         {
9801             MyEnum[] enumValues = new MyEnum[]
9802             {
9803             MyEnum.First, MyEnum.Second, MyEnum.Third
9804             }
9805 
9806             ;
9807             foreach (MyEnum a1 in enumValues)
9808             {
9809                 dynamic d1 = a1;
9810                 if ((a1 >= MyEnum.Second) != (d1 >= MyEnum.Second))
9811                 {
9812                     System.Console.WriteLine("Failed -- enum >= enum");
9813                     return false;
9814                 }
9815             }
9816 
9817             return true;
9818         }
9819     }
9820     //</Code>
9821 }
9822 
9823 
9824 
9825 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate012b.operate012b
9826 {
9827     using ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.common.common;
9828     // <Title>Relational operator</Title>
9829     // <Description>
9830     // dynamic op literals
9831     // </Description>
9832     // <RelatedBugs></RelatedBugs>
9833     //<Expects Status=success></Expects>
9834     // <Code>
9835     //<Expects Status=warning>\(94,43\).*CS0464</Expects>
9836 
9837     public class Test
9838     {
9839         public enum MyEnum
9840         {
9841             First,
9842             Second,
9843             Third
9844         }
9845 
9846         [Fact]
DynamicCSharpRunTest()9847         public static void DynamicCSharpRunTest()
9848         {
9849             Assert.Equal(0, MainMethod());
9850         }
9851 
MainMethod()9852         public static int MainMethod()
9853         {
9854             int result = 0;
9855             result += Verify.Eval(Test1);
9856             result += Verify.Eval(Test2);
9857             result += Verify.Eval(Test3);
9858             result += Verify.Eval(Test4);
9859             return result;
9860         }
9861 
Method(long l)9862         public static long Method(long l)
9863         {
9864             return l;
9865         }
9866 
9867         public dynamic dField = default(dynamic);
9868         public dynamic DPro
9869         {
9870             get
9871             {
9872                 return dField;
9873             }
9874         }
9875 
9876         public char this[char? c]
9877         {
9878             get
9879             {
9880                 return c ?? 'a';
9881             }
9882         }
9883 
Method(object d)9884         public dynamic Method(object d)
9885         {
9886             return d;
9887         }
9888 
Test1()9889         private static bool Test1()
9890         {
9891             long[] longValues = new long[]
9892             {
9893             long.MinValue, long.MinValue, 0
9894             }
9895 
9896             ;
9897             foreach (long a1 in longValues)
9898             {
9899                 dynamic d1 = a1;
9900                 if ((Method(d1) < 10) != (a1 < 10))
9901                 {
9902                     System.Console.WriteLine("Failed -- long < long");
9903                     return false;
9904                 }
9905             }
9906 
9907             return true;
9908         }
9909 
Test2()9910         private static bool Test2()
9911         {
9912             decimal?[] decimalNValues = new decimal?[]
9913             {
9914             decimal.MaxValue, int.MinValue, default (decimal), null
9915             }
9916 
9917             ;
9918             foreach (decimal? a2 in decimalNValues)
9919             {
9920                 dynamic d2 = a2;
9921                 dynamic t = new Test();
9922                 t.dField = d2;
9923                 if ((10M > t.DPro) != (10M > a2))
9924                 {
9925                     System.Console.WriteLine("Failed -- decimal? > decimal?");
9926                     return false;
9927                 }
9928             }
9929 
9930             return true;
9931         }
9932 
Test2a()9933         private static bool Test2a()
9934         {
9935             decimal?[] decimalNValues = new decimal?[]
9936             {
9937             decimal.MaxValue, int.MinValue, default (decimal), null
9938             }
9939 
9940             ;
9941             foreach (decimal? a2 in decimalNValues)
9942             {
9943                 dynamic d2 = a2;
9944                 dynamic t = new Test();
9945                 if ((t.Method(d2) > null) != (a2 > null))
9946                 {
9947                     System.Console.WriteLine("Failed -- decimal? > decimal?");
9948                     return false;
9949                 }
9950             }
9951 
9952             return true;
9953         }
9954 
Test3()9955         private static bool Test3()
9956         {
9957             char?[] charNValues = new char?[]
9958             {
9959             'a', 'b', default (char), null
9960             }
9961 
9962             ;
9963             foreach (char? a2 in charNValues)
9964             {
9965                 dynamic d2 = a2;
9966                 dynamic d = new Test();
9967                 if ((default(char) <= d[d2]) != (default(char) <= d[a2]))
9968                 {
9969                     System.Console.WriteLine("Failed -- char? <= char?");
9970                     return false;
9971                 }
9972             }
9973 
9974             return true;
9975         }
9976 
Test4()9977         private static bool Test4()
9978         {
9979             MyEnum[] enumValues = new MyEnum[]
9980             {
9981             MyEnum.First, MyEnum.Second, MyEnum.Third
9982             }
9983 
9984             ;
9985             foreach (MyEnum a1 in enumValues)
9986             {
9987                 dynamic d1 = a1;
9988                 dynamic t = new Test();
9989                 t.dField = d1;
9990                 if ((a1 >= MyEnum.Second) != (t.dField >= MyEnum.Second))
9991                 {
9992                     System.Console.WriteLine("Failed -- enum >= enum");
9993                     return false;
9994                 }
9995             }
9996 
9997             return true;
9998         }
9999     }
10000     //</Code>
10001 }
10002 
10003 
10004 
10005 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate013.operate013
10006 {
10007     using ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.common.common;
10008     // <Title>Arithmetic operator</Title>
10009     // <Description>
10010     // </Description>
10011     // <RelatedBugs></RelatedBugs>
10012     //<Expects Status=success></Expects>
10013     // <Code>
10014 
10015     public class Test
10016     {
10017         public enum MyEnum
10018         {
10019             First,
10020             Second,
10021             Third
10022         }
10023 
10024         [Fact]
DynamicCSharpRunTest()10025         public static void DynamicCSharpRunTest()
10026         {
10027             Assert.Equal(0, MainMethod());
10028         }
10029 
MainMethod()10030         public static int MainMethod()
10031         {
10032             int result = 0;
10033             result += Verify.Eval(Test1);
10034             result += Verify.Eval(Test2);
10035             result += Verify.Eval(Test3);
10036             result += Verify.Eval(Test4);
10037             result += Verify.Eval(Test5);
10038             result += Verify.Eval(Test6);
10039             result += Verify.Eval(Test7);
10040             ;
10041             return result;
10042         }
10043 
Test1()10044         private static bool Test1()
10045         {
10046             string[] stringValues = new string[]
10047             {
10048             string.Empty, "ABC", null
10049             }
10050 
10051             ;
10052             object[] objectValues = new object[]
10053             {
10054             null, 10, 10L, "10", MyEnum.First
10055             }
10056 
10057             ;
10058             foreach (string a1 in stringValues)
10059             {
10060                 foreach (object a2 in objectValues)
10061                 {
10062                     dynamic d2 = a2;
10063                     if ((a1 + d2) != (a1 + a2))
10064                     {
10065                         System.Console.WriteLine("Failed -- string + object");
10066                         return false;
10067                     }
10068                 }
10069             }
10070 
10071             return true;
10072         }
10073 
Test2()10074         private static bool Test2()
10075         {
10076             long?[] longNValues = new long?[]
10077             {
10078             10L, 30L, 0, null
10079             }
10080 
10081             ;
10082             foreach (long? a1 in longNValues)
10083             {
10084                 foreach (long? a2 in longNValues)
10085                 {
10086                     dynamic d1 = a1;
10087                     if ((d1 - a2) != (a1 - a2))
10088                     {
10089                         System.Console.WriteLine("Failed -- long? - long?");
10090                         return false;
10091                     }
10092                 }
10093             }
10094 
10095             return true;
10096         }
10097 
Test3()10098         private static bool Test3()
10099         {
10100             decimal[] decimalValues = new decimal[]
10101             {
10102             1M, 10.10M, 100.01M, 0M
10103             }
10104 
10105             ;
10106             foreach (decimal a1 in decimalValues)
10107             {
10108                 foreach (decimal a2 in decimalValues)
10109                 {
10110                     dynamic d1 = a1;
10111                     dynamic d2 = a2;
10112                     if ((d1 * d2) != (a1 * a2))
10113                     {
10114                         System.Console.WriteLine("Failed -- decimal * decimal");
10115                         return false;
10116                     }
10117                 }
10118             }
10119 
10120             return true;
10121         }
10122 
Test4()10123         private static bool Test4()
10124         {
10125             int[] intValues = new int[]
10126             {
10127             1, 2, 4, 99
10128             }
10129 
10130             ;
10131             foreach (int a1 in intValues)
10132             {
10133                 foreach (int a2 in intValues)
10134                 {
10135                     dynamic d1 = a1;
10136                     dynamic d2 = a2;
10137                     if ((d1 / d2) != (a1 / a2))
10138                     {
10139                         System.Console.WriteLine("Failed -- int / int");
10140                         return false;
10141                     }
10142                 }
10143             }
10144 
10145             return true;
10146         }
10147 
Test5()10148         private static bool Test5()
10149         {
10150             decimal?[] decimalNValues = new decimal?[]
10151             {
10152             1M, 10.10M, 100.01M, null
10153             }
10154 
10155             ;
10156             foreach (decimal? a1 in decimalNValues)
10157             {
10158                 foreach (decimal? a2 in decimalNValues)
10159                 {
10160                     dynamic d1 = a1;
10161                     if ((d1 % a2) != (a1 % a2))
10162                     {
10163                         System.Console.WriteLine("Failed -- decimal? % decimal?");
10164                         return false;
10165                     }
10166                 }
10167             }
10168 
10169             return true;
10170         }
10171 
Test6()10172         private static bool Test6()
10173         {
10174             byte[] byteValues = new byte[]
10175             {
10176             2, 30, 16, 9
10177             }
10178 
10179             ;
10180             foreach (byte a1 in byteValues)
10181             {
10182                 foreach (byte a2 in byteValues)
10183                 {
10184                     dynamic d2 = a2;
10185                     if ((a1 << d2) != (a1 << a2))
10186                     {
10187                         System.Console.WriteLine("Failed -- byte << byte");
10188                         return false;
10189                     }
10190                 }
10191             }
10192 
10193             return true;
10194         }
10195 
Test7()10196         private static bool Test7()
10197         {
10198             int?[] intNValues = new int?[]
10199             {
10200             null, 2, 4, 3
10201             }
10202 
10203             ;
10204             foreach (int? a1 in intNValues)
10205             {
10206                 foreach (int? a2 in intNValues)
10207                 {
10208                     dynamic d1 = a1;
10209                     if ((d1 >> a2) != (a1 >> a2))
10210                     {
10211                         System.Console.WriteLine("Failed -- Nullable<int> >> Nullable<int>");
10212                         return false;
10213                     }
10214                 }
10215             }
10216 
10217             return true;
10218         }
10219     }
10220     //</Code>
10221 }
10222 
10223 
10224 
10225 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate013a.operate013a
10226 {
10227     using ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.common.common;
10228     // <Title>Arithmetic operator, Compound assignment</Title>
10229     // <Description>dynamic does NOT keep nullable info either non-nullable Type or null object
10230     // </Description>
10231     // <RelatedBugs></RelatedBugs>
10232     //<Expects Status=success></Expects>
10233     // <Code>
10234 
10235     public class Test
10236     {
10237         public enum MyEnum
10238         {
10239             First,
10240             Second,
10241             Third
10242         }
10243 
10244         [Fact]
DynamicCSharpRunTest()10245         public static void DynamicCSharpRunTest()
10246         {
10247             Assert.Equal(0, MainMethod());
10248         }
10249 
MainMethod()10250         public static int MainMethod()
10251         {
10252             int result = 0;
10253             result += Verify.Eval(Test1);
10254             result += Verify.Eval(Test2);
10255             result += Verify.Eval(Test3);
10256             result += Verify.Eval(Test4);
10257             result += Verify.Eval(Test5);
10258             result += Verify.Eval(Test6);
10259             result += Verify.Eval(Test7);
10260             return result;
10261         }
10262 
Test1()10263         private static bool Test1()
10264         {
10265             string[] stringValues = new string[]
10266             {
10267             string.Empty, "ABC", null
10268             }
10269 
10270             ;
10271             object[] objectValues = new object[]
10272             {
10273             null, 10, 10L, "10", MyEnum.First
10274             }
10275 
10276             ;
10277             foreach (string a1 in stringValues)
10278             {
10279                 foreach (object a2 in objectValues)
10280                 {
10281                     var b11 = a1;
10282                     var b12 = a2;
10283                     var b21 = a1;
10284                     var b22 = a2;
10285                     dynamic d2 = a2;
10286                     if ((b11 += d2) != (b21 += b22))
10287                     {
10288                         System.Console.WriteLine("Failed -- string += object");
10289                         return false;
10290                     }
10291                 }
10292             }
10293 
10294             return true;
10295         }
10296 
Test2()10297         private static bool Test2()
10298         {
10299             long?[] longNValues = new long?[]
10300             {
10301             10L, 30L, 0, null
10302             }
10303 
10304             ;
10305             foreach (long? a1 in longNValues)
10306             {
10307                 foreach (long? a2 in longNValues)
10308                 {
10309                     var b11 = a1;
10310                     var b12 = a2;
10311                     var b21 = a1;
10312                     var b22 = a2;
10313                     dynamic d1 = a1;
10314                     // dynamic not keep ?
10315                     if (null == d1 || null == b12)
10316                         continue;
10317                     if ((d1 -= b12.Value) != (b21 -= b22))
10318                     {
10319                         System.Console.WriteLine("Failed -- long? -= long?");
10320                         return false;
10321                     }
10322                 }
10323             }
10324 
10325             return true;
10326         }
10327 
Test3()10328         private static bool Test3()
10329         {
10330             decimal[] decimalValues = new decimal[]
10331             {
10332             1M, 10.10M, 100.01M, 0M
10333             }
10334 
10335             ;
10336             foreach (decimal a1 in decimalValues)
10337             {
10338                 foreach (decimal a2 in decimalValues)
10339                 {
10340                     var b11 = a1;
10341                     var b12 = a2;
10342                     var b21 = a1;
10343                     var b22 = a2;
10344                     dynamic d1 = a1;
10345                     dynamic d2 = a2;
10346                     if ((d1 *= d2) != (b21 *= b22))
10347                     {
10348                         System.Console.WriteLine("Failed -- decimal *= decimal");
10349                         return false;
10350                     }
10351                 }
10352             }
10353 
10354             return true;
10355         }
10356 
Test4()10357         private static bool Test4()
10358         {
10359             int[] intValues = new int[]
10360             {
10361             1, 2, 4, 99
10362             }
10363 
10364             ;
10365             foreach (int a1 in intValues)
10366             {
10367                 foreach (int a2 in intValues)
10368                 {
10369                     var b11 = a1;
10370                     var b12 = a2;
10371                     var b21 = a1;
10372                     var b22 = a2;
10373                     dynamic d1 = a1;
10374                     dynamic d2 = a2;
10375                     if ((d1 /= d2) != (b21 /= b22))
10376                     {
10377                         System.Console.WriteLine("Failed -- int /= int");
10378                         return false;
10379                     }
10380                 }
10381             }
10382 
10383             return true;
10384         }
10385 
Test5()10386         private static bool Test5()
10387         {
10388             decimal?[] decimalNValues = new decimal?[]
10389             {
10390             1M, 10.10M, 100.01M
10391             }
10392 
10393             ;
10394             foreach (decimal? a1 in decimalNValues)
10395             {
10396                 foreach (decimal? a2 in decimalNValues)
10397                 {
10398                     var b11 = a1;
10399                     var b12 = a2;
10400                     var b21 = a1;
10401                     var b22 = a2;
10402                     dynamic d1 = a1;
10403                     if ((d1 %= b12.Value) != (b21 %= b22))
10404                     {
10405                         System.Console.WriteLine("Failed -- decimal? %= decimal?");
10406                         return false;
10407                     }
10408                 }
10409             }
10410 
10411             return true;
10412         }
10413 
Test6()10414         private static bool Test6()
10415         {
10416             byte[] byteValues = new byte[]
10417             {
10418             2, 30, 16, 9
10419             }
10420 
10421             ;
10422             foreach (byte a1 in byteValues)
10423             {
10424                 foreach (byte a2 in byteValues)
10425                 {
10426                     var b11 = a1;
10427                     var b12 = a2;
10428                     var b21 = a1;
10429                     var b22 = a2;
10430                     dynamic d2 = a2;
10431                     if (unchecked(b11 <<= d2) != unchecked(b21 <<= b22))
10432                     {
10433                         System.Console.WriteLine("Failed -- byte <<= byte");
10434                         return false;
10435                     }
10436                 }
10437             }
10438 
10439             return true;
10440         }
10441 
Test7()10442         private static bool Test7()
10443         {
10444             int?[] intNValues = new int?[]
10445             { /*null,*/
10446             2, 4, 3
10447             }
10448 
10449             ;
10450             foreach (int? a1 in intNValues)
10451             {
10452                 foreach (int? a2 in intNValues)
10453                 {
10454                     var b11 = a1;
10455                     var b12 = a2;
10456                     var b21 = a1;
10457                     var b22 = a2;
10458                     dynamic d1 = a1;
10459                     if ((d1 >>= b12) != (b21 >>= b22))
10460                     {
10461                         System.Console.WriteLine("Failed -- Nullable<int> >>= Nullable<int>");
10462                         return false;
10463                     }
10464                 }
10465             }
10466 
10467             return true;
10468         }
10469     }
10470     //</Code>
10471 }
10472 
10473 
10474 
10475 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate013b.operate013b
10476 {
10477     using ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.common.common;
10478     // <Title>Arithmetic operator</Title>
10479     // <Description>
10480     // dynamic op literals
10481     // </Description>
10482     // <RelatedBugs></RelatedBugs>
10483     //<Expects Status=success></Expects>
10484     // <Code>
10485     //<Expects Status=warning>\(113,33\).*CS0458</Expects>
10486 
10487     public class Test
10488     {
10489         [Fact]
DynamicCSharpRunTest()10490         public static void DynamicCSharpRunTest()
10491         {
10492             Assert.Equal(0, MainMethod());
10493         }
10494 
MainMethod()10495         public static int MainMethod()
10496         {
10497             int result = 0;
10498             result += Verify.Eval(Test1);
10499             result += Verify.Eval(Test1a);
10500             result += Verify.Eval(Test2);
10501             result += Verify.Eval(Test3);
10502             result += Verify.Eval(Test4);
10503             result += Verify.Eval(Test5);
10504             result += Verify.Eval(Test6);
10505             result += Verify.Eval(Test7);
10506             ;
10507             return result;
10508         }
10509 
Test1()10510         private static bool Test1()
10511         {
10512             object[] objectValues = new object[]
10513             {
10514             10, 10L, "10"
10515             }
10516 
10517             ;
10518             foreach (object a2 in objectValues)
10519             {
10520                 dynamic d2 = a2;
10521                 if (("ABC" + d2) != ("ABC" + 10))
10522                 {
10523                     System.Console.WriteLine("Failed -- string + object");
10524                     return false;
10525                 }
10526             }
10527 
10528             return true;
10529         }
10530 
Test1a()10531         private static bool Test1a()
10532         {
10533             object[] objectValues = new object[]
10534             {
10535             string.Empty, new Test(), null
10536             }
10537 
10538             ;
10539             foreach (object a2 in objectValues)
10540             {
10541                 dynamic d2 = a2;
10542                 if (("ABC" + d2) != ("ABC" + a2))
10543                 {
10544                     System.Console.WriteLine("Failed -- string + object");
10545                     return false;
10546                 }
10547             }
10548 
10549             return true;
10550         }
10551 
Test2()10552         private static bool Test2()
10553         {
10554             long?[] longNValues = new long?[]
10555             {
10556             10L, 30L, 0, null
10557             }
10558 
10559             ;
10560             foreach (long? a1 in longNValues)
10561             {
10562                 dynamic d1 = a1;
10563                 if ((d1 - 10) != (a1 - 10))
10564                 {
10565                     System.Console.WriteLine("Failed -- long? - long?");
10566                     return false;
10567                 }
10568             }
10569 
10570             return true;
10571         }
10572 
Test3()10573         private static bool Test3()
10574         {
10575             decimal[] decimalValues = new decimal[]
10576             {
10577             1M, 10.10M, 100.01M, 0M
10578             }
10579 
10580             ;
10581             foreach (decimal a2 in decimalValues)
10582             {
10583                 dynamic d2 = a2;
10584                 if ((2M * d2) != (2M * a2))
10585                 {
10586                     System.Console.WriteLine("Failed -- decimal * decimal");
10587                     return false;
10588                 }
10589             }
10590 
10591             return true;
10592         }
10593 
Test4()10594         private static bool Test4()
10595         {
10596             int[] intValues = new int[]
10597             {
10598             1, 2, 4, 99
10599             }
10600 
10601             ;
10602             foreach (int a1 in intValues)
10603             {
10604                 dynamic d1 = a1;
10605                 if ((d1 / 3) != (a1 / 3))
10606                 {
10607                     System.Console.WriteLine("Failed -- int / int");
10608                     return false;
10609                 }
10610             }
10611 
10612             return true;
10613         }
10614 
Test5()10615         private static bool Test5()
10616         {
10617             decimal?[] decimalNValues = new decimal?[]
10618             {
10619             1M, 10.10M, 100.01M, null
10620             }
10621 
10622             ;
10623             foreach (decimal? a1 in decimalNValues)
10624             {
10625                 dynamic d1 = a1;
10626                 if ((d1 % null) != (a1 % null))
10627                 {
10628                     System.Console.WriteLine("Failed -- decimal? % decimal?");
10629                     return false;
10630                 }
10631             }
10632 
10633             return true;
10634         }
10635 
Test6()10636         private static bool Test6()
10637         {
10638             byte[] byteValues = new byte[]
10639             {
10640             2, 30, 16, 9
10641             }
10642 
10643             ;
10644             foreach (byte a2 in byteValues)
10645             {
10646                 dynamic d2 = a2;
10647                 if ((30 << d2) != (30 << a2))
10648                 {
10649                     System.Console.WriteLine("Failed -- byte << byte");
10650                     return false;
10651                 }
10652             }
10653 
10654             return true;
10655         }
10656 
Test7()10657         private static bool Test7()
10658         {
10659             int?[] intNValues = new int?[]
10660             {
10661             null, 2, 4, 3
10662             }
10663 
10664             ;
10665             foreach (int? a1 in intNValues)
10666             {
10667                 dynamic d1 = a1;
10668                 if ((d1 >> 2) != (a1 >> 2))
10669                 {
10670                     System.Console.WriteLine("Failed -- Nullable<int> >> Nullable<int>");
10671                     return false;
10672                 }
10673             }
10674 
10675             return true;
10676         }
10677     }
10678     //</Code>
10679 }
10680 
10681 
10682 
10683 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate014.operate014
10684 {
10685     using ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.common.common;
10686     // <Title>Short circuiting operators</Title>
10687     // <Description>
10688     // </Description>
10689     // <RelatedBugs></RelatedBugs>
10690     //<Expects Status=success></Expects>
10691     // <Code>
10692 
10693     public class Test
10694     {
10695         public static bool isHit = false;
10696         [Fact]
DynamicCSharpRunTest()10697         public static void DynamicCSharpRunTest()
10698         {
10699             Assert.Equal(0, MainMethod());
10700         }
10701 
MainMethod()10702         public static int MainMethod()
10703         {
10704             int result = 0;
10705             result += Verify.Eval(Test1);
10706             result += Verify.Eval(Test2);
10707             result += Verify.Eval(Test3);
10708             result += Verify.Eval(Test4);
10709             return result;
10710         }
10711 
Test1()10712         private static bool Test1()
10713         {
10714             dynamic d1 = true;
10715             isHit = false;
10716             if (d1 || BoolValue)
10717             {
10718                 //d1 is always true, BoolValue is never hit
10719                 if (isHit)
10720                 {
10721                     System.Console.WriteLine("Failed -- bool || bool as circuiting operators");
10722                     return false;
10723                 }
10724             }
10725             else
10726             {
10727                 // never hit here.
10728                 System.Console.WriteLine("Failed -- bool || bool as circuiting operators");
10729                 return false;
10730             }
10731 
10732             return true;
10733         }
10734 
Test2()10735         private static bool Test2()
10736         {
10737             dynamic d1 = false;
10738             isHit = false;
10739             if (d1 && BoolValue)
10740             {
10741                 // never hit here.
10742                 System.Console.WriteLine("Failed -- bool && bool as circuiting operators");
10743                 return false;
10744             }
10745             else
10746             {
10747                 //d1 is always false, BoolValue is never hit
10748                 if (isHit)
10749                 {
10750                     System.Console.WriteLine("Failed -- bool && bool as circuiting operators");
10751                     return false;
10752                 }
10753             }
10754 
10755             return true;
10756         }
10757 
Test3()10758         private static bool Test3()
10759         {
10760             dynamic d1 = false;
10761             isHit = false;
10762             dynamic m = d1 ? StringValue : "ABC";
10763             if (isHit || m != "ABC")
10764             {
10765                 System.Console.WriteLine("Failed -- ? : operator");
10766                 return false;
10767             }
10768 
10769             return true;
10770         }
10771 
Test4()10772         private static bool Test4()
10773         {
10774             dynamic d1 = true;
10775             isHit = false;
10776             dynamic value = 20;
10777             dynamic m = d1 ? value : IntValue;
10778             if (isHit || m != 20)
10779             {
10780                 System.Console.WriteLine("Failed -- ? : operator");
10781                 return false;
10782             }
10783 
10784             return true;
10785         }
10786 
10787         public static bool BoolValue
10788         {
10789             get
10790             {
10791                 isHit = true;
10792                 return true;
10793             }
10794 
10795             set
10796             {
10797             }
10798         }
10799 
10800         public static string StringValue
10801         {
10802             get
10803             {
10804                 isHit = true;
10805                 return string.Empty;
10806             }
10807 
10808             set
10809             {
10810             }
10811         }
10812 
10813         public static int IntValue
10814         {
10815             get
10816             {
10817                 isHit = true;
10818                 return 10;
10819             }
10820 
10821             set
10822             {
10823             }
10824         }
10825     }
10826     //</Code>
10827 }
10828 
10829 
10830 
10831 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate014b.operate014b
10832 {
10833     using ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.common.common;
10834     // <Title>User defined short circuiting operators</Title>
10835     // <Description>
10836     // Unlike in the static world, we can't know the type we care about (the runtime type) for the right operand,
10837     // as evaluating the right operand expression to get the type may result in side effects.
10838     // Therefore, we will only ever evaluate the right operand if we know we need to return it.
10839     // </Description>
10840     // <RelatedBugs></RelatedBugs>
10841     // <Expects Status=success></Expects>
10842     // <Code>
10843     using Microsoft.CSharp.RuntimeBinder;
10844 
10845     public class MyOpClass
10846     {
operator bool(MyOpClass p)10847         public static explicit operator bool (MyOpClass p)
10848         {
10849             Test.isCallConvert = true;
10850             return true;
10851         }
10852 
operator true(MyOpClass p)10853         public static bool operator true(MyOpClass p)
10854         {
10855             Test.isCallTrue = true;
10856             return false;
10857         }
10858 
operator false(MyOpClass p)10859         public static bool operator false(MyOpClass p)
10860         {
10861             Test.isCallFalse = true;
10862             return false;
10863         }
10864 
operator &(MyOpClass p1, MyOpClass p2)10865         public static MyOpClass operator &(MyOpClass p1, MyOpClass p2)
10866         {
10867             Test.isCallOpAnd = true;
10868             return p1;
10869         }
10870 
operator |(MyOpClass p1, MyOpClass p2)10871         public static MyOpClass operator |(MyOpClass p1, MyOpClass p2)
10872         {
10873             Test.isCallOpOr = true;
10874             return p2;
10875         }
10876     }
10877 
10878     public class MyOpClassWithDiffType
10879     {
operator bool(MyOpClassWithDiffType p)10880         public static explicit operator bool (MyOpClassWithDiffType p)
10881         {
10882             Test.isCallConvert = true;
10883             return true;
10884         }
10885 
operator true(MyOpClassWithDiffType p)10886         public static bool operator true(MyOpClassWithDiffType p)
10887         {
10888             Test.isCallTrue = true;
10889             return true;
10890         }
10891 
operator false(MyOpClassWithDiffType p)10892         public static bool operator false(MyOpClassWithDiffType p)
10893         {
10894             Test.isCallFalse = true;
10895             return false;
10896         }
10897 
operator &(MyOpClassWithDiffType p1, int p2)10898         public static MyOpClassWithDiffType operator &(MyOpClassWithDiffType p1, int p2)
10899         {
10900             Test.isCallOpAnd = true;
10901             return p1;
10902         }
10903 
operator |(int p1, MyOpClassWithDiffType p2)10904         public static MyOpClassWithDiffType operator |(int p1, MyOpClassWithDiffType p2)
10905         {
10906             Test.isCallOpOr = true;
10907             return p2;
10908         }
10909     }
10910 
10911     public class MyOpClassWithDiffType2
10912     {
operator bool(MyOpClassWithDiffType2 p)10913         public static explicit operator bool (MyOpClassWithDiffType2 p)
10914         {
10915             Test.isCallConvert = true;
10916             return true;
10917         }
10918 
operator true(MyOpClassWithDiffType2 p)10919         public static bool operator true(MyOpClassWithDiffType2 p)
10920         {
10921             Test.isCallTrue = true;
10922             return false;
10923         }
10924 
operator false(MyOpClassWithDiffType2 p)10925         public static bool operator false(MyOpClassWithDiffType2 p)
10926         {
10927             Test.isCallFalse = true;
10928             return true;
10929         }
10930 
operator &(MyOpClassWithDiffType2 p1, int p2)10931         public static MyOpClassWithDiffType2 operator &(MyOpClassWithDiffType2 p1, int p2)
10932         {
10933             Test.isCallOpAnd = true;
10934             return p1;
10935         }
10936 
operator |(int p1, MyOpClassWithDiffType2 p2)10937         public static MyOpClassWithDiffType2 operator |(int p1, MyOpClassWithDiffType2 p2)
10938         {
10939             Test.isCallOpOr = true;
10940             return p2;
10941         }
10942     }
10943 
10944     public class MyOpClassWithErrorReturnType
10945     {
operator bool(MyOpClassWithErrorReturnType p)10946         public static explicit operator bool (MyOpClassWithErrorReturnType p)
10947         {
10948             Test.isCallConvert = true;
10949             return true;
10950         }
10951 
operator true(MyOpClassWithErrorReturnType p)10952         public static bool operator true(MyOpClassWithErrorReturnType p)
10953         {
10954             Test.isCallTrue = true;
10955             return true;
10956         }
10957 
operator false(MyOpClassWithErrorReturnType p)10958         public static bool operator false(MyOpClassWithErrorReturnType p)
10959         {
10960             Test.isCallFalse = true;
10961             return false;
10962         }
10963 
operator &(MyOpClassWithErrorReturnType p1, MyOpClassWithErrorReturnType p2)10964         public static int operator &(MyOpClassWithErrorReturnType p1, MyOpClassWithErrorReturnType p2)
10965         {
10966             Test.isCallOpAnd = true;
10967             return 1;
10968         }
10969 
operator |(MyOpClassWithErrorReturnType p1, MyOpClassWithErrorReturnType p2)10970         public static int operator |(MyOpClassWithErrorReturnType p1, MyOpClassWithErrorReturnType p2)
10971         {
10972             Test.isCallOpOr = true;
10973             return 2;
10974         }
10975     }
10976 
10977     public class MyOpClassWithErrorReturnType2
10978     {
operator bool(MyOpClassWithErrorReturnType2 p)10979         public static explicit operator bool (MyOpClassWithErrorReturnType2 p)
10980         {
10981             Test.isCallConvert = true;
10982             return true;
10983         }
10984 
operator true(MyOpClassWithErrorReturnType2 p)10985         public static bool operator true(MyOpClassWithErrorReturnType2 p)
10986         {
10987             Test.isCallTrue = true;
10988             return false;
10989         }
10990 
operator false(MyOpClassWithErrorReturnType2 p)10991         public static bool operator false(MyOpClassWithErrorReturnType2 p)
10992         {
10993             Test.isCallFalse = true;
10994             return true;
10995         }
10996 
operator &(MyOpClassWithErrorReturnType2 p1, MyOpClassWithErrorReturnType2 p2)10997         public static int operator &(MyOpClassWithErrorReturnType2 p1, MyOpClassWithErrorReturnType2 p2)
10998         {
10999             Test.isCallOpAnd = true;
11000             return 1;
11001         }
11002 
operator |(MyOpClassWithErrorReturnType2 p1, MyOpClassWithErrorReturnType2 p2)11003         public static int operator |(MyOpClassWithErrorReturnType2 p1, MyOpClassWithErrorReturnType2 p2)
11004         {
11005             Test.isCallOpOr = true;
11006             return 2;
11007         }
11008     }
11009 
11010     public class Test
11011     {
11012         public static bool isCallConvert = false;
11013         public static bool isCallTrue = false;
11014         public static bool isCallFalse = false;
11015         public static bool isCallOpAnd = false;
11016         public static bool isCallOpOr = false;
ClearFlags()11017         public static void ClearFlags()
11018         {
11019             isCallConvert = false;
11020             isCallTrue = false;
11021             isCallFalse = false;
11022             isCallOpAnd = false;
11023             isCallOpOr = false;
11024         }
11025 
11026         [Fact]
DynamicCSharpRunTest()11027         public static void DynamicCSharpRunTest()
11028         {
11029             Assert.Equal(0, MainMethod());
11030         }
11031 
MainMethod()11032         public static int MainMethod()
11033         {
11034             int result = 0;
11035             result += Verify.Eval(TestAndOpWithSameTypeAndReturnType);
11036             result += Verify.Eval(TestAndOpWithDiffType);
11037             result += Verify.Eval(TestAndOpWithDiffType2);
11038             result += Verify.Eval(TestAndOpWithSameTypeButWrongReturnType);
11039             result += Verify.Eval(TestAndOpWithSameTypeButWrongReturnType2);
11040             result += Verify.Eval(TestOrOpWithSameTypeAndReturnType);
11041             result += Verify.Eval(TestOrOpWithDiffType);
11042             result += Verify.Eval(TestOrOpWithDiffType2);
11043             result += Verify.Eval(TestOrOpWithSameTypeButWrongReturnType);
11044             result += Verify.Eval(TestOrOpWithSameTypeButWrongReturnType2);
11045             return result;
11046         }
11047 
11048         #region conditional logical and operator
TestAndOpWithSameTypeAndReturnType()11049         private static bool TestAndOpWithSameTypeAndReturnType()
11050         {
11051             ClearFlags();
11052             dynamic d1 = new MyOpClass();
11053             dynamic d2 = new MyOpClass();
11054             dynamic dr = d1 && d2;
11055             if (dr.GetType() != typeof(MyOpClass))
11056             {
11057                 System.Console.WriteLine("Failed -- got wrong return type");
11058                 return false;
11059             }
11060 
11061             if (dr != d1)
11062             {
11063                 System.Console.WriteLine("Failed -- got wrong result");
11064                 return false;
11065             }
11066 
11067             if (!(isCallFalse && isCallOpAnd && !isCallTrue && !isCallConvert && !isCallOpOr))
11068             {
11069                 System.Console.WriteLine("Failed -- executed error ops. isCallConvert[{0}, isCallTrue[{1}], isCallFalse[{2}], isCallOpAnd[{3}], isCallOpOr[{4}], ", isCallConvert, isCallTrue, isCallFalse, isCallOpAnd, isCallOpOr);
11070                 return false;
11071             }
11072 
11073             return true;
11074         }
11075 
TestAndOpWithDiffType()11076         private static bool TestAndOpWithDiffType()
11077         {
11078             ClearFlags();
11079             dynamic d1 = new MyOpClassWithDiffType();
11080             dynamic d2 = 10;
11081             try
11082             {
11083                 dynamic dr = d1 && d2;
11084                 System.Console.WriteLine("Failed -- didn't get RuntimeBinderException");
11085             }
11086             catch (RuntimeBinderException e)
11087             {
11088                 if (ErrorVerifier.Verify(ErrorMessageId.BadBoolOp, e.Message, "MyOpClassWithDiffType.operator &(MyOpClassWithDiffType, int)"))
11089                     return true;
11090             }
11091 
11092             return false;
11093         }
11094 
TestAndOpWithDiffType2()11095         private static bool TestAndOpWithDiffType2()
11096         {
11097             ClearFlags();
11098             dynamic d1 = new MyOpClassWithDiffType2();
11099             dynamic d2 = 10;
11100             dynamic dr = d1 && d2;
11101             if (dr.GetType() != typeof(MyOpClassWithDiffType2))
11102             {
11103                 System.Console.WriteLine("Failed -- got wrong return type");
11104                 return false;
11105             }
11106 
11107             if (dr != d1)
11108             {
11109                 System.Console.WriteLine("Failed -- got wrong result");
11110                 return false;
11111             }
11112 
11113             if (!(isCallFalse && !isCallOpAnd && !isCallTrue && !isCallConvert && !isCallOpOr))
11114             {
11115                 System.Console.WriteLine("Failed -- executed error ops. isCallConvert[{0}, isCallTrue[{1}], isCallFalse[{2}], isCallOpAnd[{3}], isCallOpOr[{4}], ", isCallConvert, isCallTrue, isCallFalse, isCallOpAnd, isCallOpOr);
11116                 return false;
11117             }
11118 
11119             return true;
11120         }
11121 
TestAndOpWithSameTypeButWrongReturnType()11122         private static bool TestAndOpWithSameTypeButWrongReturnType()
11123         {
11124             ClearFlags();
11125             dynamic d1 = new MyOpClassWithErrorReturnType();
11126             dynamic d2 = new MyOpClassWithErrorReturnType();
11127             try
11128             {
11129                 dynamic dr = d1 && d2;
11130                 System.Console.WriteLine("Failed -- didn't get RuntimeBinderException");
11131             }
11132             catch (RuntimeBinderException e)
11133             {
11134                 if (ErrorVerifier.Verify(ErrorMessageId.BadBoolOp, e.Message, "MyOpClassWithErrorReturnType.operator &(MyOpClassWithErrorReturnType, MyOpClassWithErrorReturnType)"))
11135                     return true;
11136             }
11137 
11138             return false;
11139         }
11140 
TestAndOpWithSameTypeButWrongReturnType2()11141         private static bool TestAndOpWithSameTypeButWrongReturnType2()
11142         {
11143             ClearFlags();
11144             dynamic d1 = new MyOpClassWithErrorReturnType2();
11145             dynamic d2 = new MyOpClassWithErrorReturnType2();
11146             dynamic dr = d1 && d2;
11147             if (dr.GetType() != typeof(MyOpClassWithErrorReturnType2))
11148             {
11149                 System.Console.WriteLine("Failed -- got wrong return type");
11150                 return false;
11151             }
11152 
11153             if (dr != d1)
11154             {
11155                 System.Console.WriteLine("Failed -- got wrong result");
11156                 return false;
11157             }
11158 
11159             if (!(isCallFalse && !isCallOpAnd && !isCallTrue && !isCallConvert && !isCallOpOr))
11160             {
11161                 System.Console.WriteLine("Failed -- executed error ops. isCallConvert[{0}, isCallTrue[{1}], isCallFalse[{2}], isCallOpAnd[{3}], isCallOpOr[{4}], ", isCallConvert, isCallTrue, isCallFalse, isCallOpAnd, isCallOpOr);
11162                 return false;
11163             }
11164 
11165             return true;
11166         }
11167 
11168         #endregion
11169         #region conditional logical or operator
TestOrOpWithSameTypeAndReturnType()11170         private static bool TestOrOpWithSameTypeAndReturnType()
11171         {
11172             ClearFlags();
11173             dynamic d1 = new MyOpClass();
11174             dynamic d2 = new MyOpClass();
11175             dynamic dr = d1 || d2;
11176             if (dr.GetType() != typeof(MyOpClass))
11177             {
11178                 System.Console.WriteLine("Failed -- got wrong return type");
11179                 return false;
11180             }
11181 
11182             if (dr != d2)
11183             {
11184                 System.Console.WriteLine("Failed -- got wrong result");
11185                 return false;
11186             }
11187 
11188             if (!(isCallTrue && isCallOpOr && !isCallFalse && !isCallConvert && !isCallOpAnd))
11189             {
11190                 System.Console.WriteLine("Failed -- executed error ops. isCallConvert[{0}, isCallTrue[{1}], isCallFalse[{2}], isCallOpAnd[{3}], isCallOpOr[{4}], ", isCallConvert, isCallTrue, isCallFalse, isCallOpAnd, isCallOpOr);
11191                 return false;
11192             }
11193 
11194             return true;
11195         }
11196 
TestOrOpWithDiffType()11197         private static bool TestOrOpWithDiffType()
11198         {
11199             ClearFlags();
11200             dynamic d1 = 10;
11201             dynamic d2 = new MyOpClassWithDiffType();
11202             try
11203             {
11204                 dynamic dr = d1 || d2;
11205                 System.Console.WriteLine("Failed -- didn't get RuntimeBinderException");
11206             }
11207             catch (RuntimeBinderException e)
11208             {
11209                 if (ErrorVerifier.Verify(ErrorMessageId.NoImplicitConv, e.Message, "int", "bool"))
11210                     return true;
11211             }
11212 
11213             return false;
11214         }
11215 
TestOrOpWithDiffType2()11216         private static bool TestOrOpWithDiffType2()
11217         {
11218             ClearFlags();
11219             dynamic d1 = 10;
11220             dynamic d2 = new MyOpClassWithDiffType2();
11221             try
11222             {
11223                 dynamic dr = d1 || d2;
11224                 System.Console.WriteLine("Failed -- didn't get RuntimeBinderException");
11225             }
11226             catch (RuntimeBinderException e)
11227             {
11228                 if (ErrorVerifier.Verify(ErrorMessageId.NoImplicitConv, e.Message, "int", "bool"))
11229                     return true;
11230             }
11231 
11232             return false;
11233         }
11234 
TestOrOpWithSameTypeButWrongReturnType()11235         private static bool TestOrOpWithSameTypeButWrongReturnType()
11236         {
11237             ClearFlags();
11238             dynamic d1 = new MyOpClassWithErrorReturnType();
11239             dynamic d2 = new MyOpClassWithErrorReturnType();
11240             dynamic dr = d1 || d2;
11241             if (dr.GetType() != typeof(MyOpClassWithErrorReturnType))
11242             {
11243                 System.Console.WriteLine("Failed -- got wrong return type");
11244                 return false;
11245             }
11246 
11247             if (dr != d1)
11248             {
11249                 System.Console.WriteLine("Failed -- got wrong result");
11250                 return false;
11251             }
11252 
11253             if (!(isCallTrue && !isCallOpOr && !isCallFalse && !isCallConvert && !isCallOpAnd))
11254             {
11255                 System.Console.WriteLine("Failed -- executed error ops. isCallConvert[{0}, isCallTrue[{1}], isCallFalse[{2}], isCallOpAnd[{3}], isCallOpOr[{4}], ", isCallConvert, isCallTrue, isCallFalse, isCallOpAnd, isCallOpOr);
11256                 return false;
11257             }
11258 
11259             return true;
11260         }
11261 
TestOrOpWithSameTypeButWrongReturnType2()11262         private static bool TestOrOpWithSameTypeButWrongReturnType2()
11263         {
11264             ClearFlags();
11265             dynamic d1 = new MyOpClassWithErrorReturnType2();
11266             dynamic d2 = new MyOpClassWithErrorReturnType2();
11267             try
11268             {
11269                 dynamic dr = d1 || d2;
11270                 System.Console.WriteLine("Failed -- didn't get RuntimeBinderException");
11271             }
11272             catch (RuntimeBinderException e)
11273             {
11274                 if (ErrorVerifier.Verify(ErrorMessageId.BadBoolOp, e.Message, "MyOpClassWithErrorReturnType2.operator |(MyOpClassWithErrorReturnType2, MyOpClassWithErrorReturnType2)"))
11275                     return true;
11276             }
11277 
11278             return false;
11279         }
11280         #endregion
11281     }
11282     // </Code>
11283 }
11284 
11285 
11286 
11287 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate015.operate015
11288 {
11289     // <Title> Operator -.is, as</Title>
11290     // <Description></Description>
11291     // <RelatedBugs></RelatedBugs>
11292     //<Expects Status=success></Expects>
11293     // <Code>
11294     using System.Collections.Generic;
11295 
11296     public class A
11297     {
11298         [Fact]
DynamicCSharpRunTest()11299         public static void DynamicCSharpRunTest()
11300         {
11301             Assert.Equal(0, MainMethod());
11302         }
11303 
MainMethod()11304         public static int MainMethod()
11305         {
11306             object[] x = new[]
11307             {
11308             ""
11309             }
11310 
11311             ;
11312             dynamic[] y = x as dynamic[];
11313             bool ret = (x == y);
11314             ret &= (y is IList<string>); // used to be false
11315             ret &= (x is IList<string>);
11316             return ret ? 0 : 1;
11317         }
11318     }
11319     //</Code>
11320 }
11321 
11322 
11323 
11324 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate016.operate016
11325 {
11326     // <Title> Operator -.is, as</Title>
11327     // <Description></Description>
11328     // <RelatedBugs></RelatedBugs>
11329     //<Expects Status=success></Expects>
11330     // <Code>
11331 
11332     public class A
11333     {
11334         [Fact]
DynamicCSharpRunTest()11335         public static void DynamicCSharpRunTest()
11336         {
11337             Assert.Equal(0, MainMethod());
11338         }
11339 
MainMethod()11340         public static int MainMethod()
11341         {
11342             bool? b = true;
11343             dynamic d = b;
11344             if (!d == !b)
11345                 return 0;
11346             return 1;
11347         }
11348     }
11349     //</Code>
11350 }
11351 
11352 
11353 
11354 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate017.operate017
11355 {
11356     using ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.common.common;
11357     // <Title>Unary operators with operand null</Title>
11358     // <Description>
11359     // The related
11360     // </Description>
11361     // <RelatedBugs></RelatedBugs>
11362     // <Expects Status=success></Expects>
11363     // <Code>
11364     using System;
11365     using Microsoft.CSharp.RuntimeBinder;
11366 
11367     public class Test
11368     {
11369         [Fact]
DynamicCSharpRunTest()11370         public static void DynamicCSharpRunTest()
11371         {
11372             Assert.Equal(0, MainMethod());
11373         }
11374 
MainMethod()11375         public static int MainMethod()
11376         {
11377             int result = 0;
11378             result += Verify.Eval(() => TestUnaryOp(d => +d, "+"), "Unary +");
11379             result += Verify.Eval(() => TestUnaryOp(d => -d, "-"), "Unary -");
11380             result += Verify.Eval(() => TestUnaryOp(d => !d, "!"), "Unary *");
11381             result += Verify.Eval(() => TestUnaryOp(d => ~d, "~"), "Unary /");
11382             result += Verify.Eval(Test5, "Cast");
11383             // result += Verify.Eval(() => TestUnaryOp(d => ++d, "++"), "pre ++");
11384             result += Verify.Eval(() => TestIncDec(d => ++d), "pre ++");
11385             result += Verify.Eval(() => TestIncDec(d => d++), "post ++");
11386             result += Verify.Eval(() => TestIncDec(d => --d), "pre --");
11387             result += Verify.Eval(() => TestIncDec(d => d--), "post --");
11388             result += Verify.Eval(Test10, "checked");
11389             result += Verify.Eval(Test11, "unchecked");
11390             return result;
11391         }
11392 
TestUnaryOp(Func<dynamic, dynamic> exp, string op)11393         private static bool TestUnaryOp(Func<dynamic, dynamic> exp, string op)
11394         {
11395             dynamic d = null;
11396             try
11397             {
11398                 if (exp(d) != null)
11399                     return false;
11400             }
11401             catch (RuntimeBinderException e)
11402             {
11403                 if (ErrorVerifier.Verify(ErrorMessageId.BadUnaryOp, e.Message, op, ErrorVerifier.GetErrorElement(ErrorElementId.NULL)))
11404                     return true;
11405             }
11406 
11407             return false;
11408         }
11409 
Test5()11410         private static bool Test5()
11411         {
11412             dynamic d = null;
11413             if (((string)d) != null)
11414                 return false;
11415             return true;
11416         }
11417 
TestIncDec(Func<dynamic, dynamic> exp)11418         private static bool TestIncDec(Func<dynamic, dynamic> exp)
11419         {
11420             dynamic d = null;
11421             try
11422             {
11423                 if (exp(d) != null)
11424                     return false;
11425             }
11426             catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
11427             {
11428                 bool ret = ErrorVerifier.Verify(ErrorMessageId.IncrementLvalueExpected, e.Message);
11429                 return ret;
11430             }
11431 
11432             return false;
11433         }
11434 
Test10()11435         private static bool Test10()
11436         {
11437             dynamic d = null;
11438             if ((checked(d)) != null)
11439                 return false;
11440             return true;
11441         }
11442 
Test11()11443         private static bool Test11()
11444         {
11445             dynamic d = null;
11446             if ((unchecked(d)) != null)
11447                 return false;
11448             return true;
11449         }
11450     }
11451     //</Code>
11452 }
11453 
11454 
11455 
11456 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate018.operate018
11457 {
11458     using ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.common.common;
11459     // <Title>Binary operators with both operands are null</Title>
11460     // <Description>
11461     // </Description>
11462     // <RelatedBugs></RelatedBugs>
11463     // <Expects Status=success></Expects>
11464     // <Code>
11465 #pragma warning disable 0458 // expression always null warning
11466 
11467 #pragma warning disable 0464 // Comparing with null of type 'int?' always produces 'false'
11468 
11469     using System;
11470     using Microsoft.CSharp.RuntimeBinder;
11471 
11472     public class Test
11473     {
11474         [Fact]
DynamicCSharpRunTest()11475         public static void DynamicCSharpRunTest()
11476         {
11477             Assert.Equal(0, MainMethod());
11478         }
11479 
MainMethod()11480         public static int MainMethod()
11481         {
11482             int result = 0;
11483             //dynamic d2 = null + null; // error CS0034: Operator '+' is ambiguous on operands of type '<null>' and '<null>'
11484             //int? ni = null;
11485             //dynamic d3 = ni + null;  // will get null
11486             result += Verify.Eval(() => TestBinaryOp(d => null + d, "+"), "binary +");
11487             result += Verify.Eval(() => TestResultIsNull(d =>
11488             {
11489                 int? ni1 = null;
11490                 int? ni = ni1 + null;
11491                 return d + ni;
11492             }
11493 
11494             ), "binary /");
11495             result += Verify.Eval(() => TestResultIsNull(d => d - (null - null)), "binary -");
11496             result += Verify.Eval(() => TestResultIsNull(d =>
11497             {
11498                 dynamic d2 = null * null;
11499                 return d * d2;
11500             }
11501 
11502             ), "binary *");
11503             result += Verify.Eval(() => TestResultIsNull(d =>
11504             {
11505                 int? ni = null / null;
11506                 return ni / d;
11507             }
11508 
11509             ), "binary /");
11510             result += Verify.Eval(() => TestResultIsNull(d => null % d), "binary %");
11511             result += Verify.Eval(() => TestResultIsNull(d => d << (null << null)), "binary <<");
11512             result += Verify.Eval(() => TestResultIsNull(d =>
11513             {
11514                 int? ni = null >> null;
11515                 return d >> ni;
11516             }
11517 
11518             ), "binary >>");
11519             result += Verify.Eval(() => TestBinaryOpRelation(d => d == null), "binary ==");
11520             result += Verify.Eval(() => TestBinaryOpRelation(d => !(null != d)), "binary !=");
11521             result += Verify.Eval(() => TestBinaryOpRelation(d => !(null > null)), "binary >");
11522             result += Verify.Eval(() => TestBinaryOpRelation(d => !(d > null)), "binary >");
11523             result += Verify.Eval(() => TestBinaryOpRelation(d =>
11524             {
11525                 dynamic d2 = null;
11526                 return !(d >= d2);
11527             }
11528 
11529             ), "binary >=");
11530             result += Verify.Eval(() => TestBinaryOpRelation(d =>
11531             {
11532                 int? ni = null;
11533                 return !(ni < d);
11534             }
11535 
11536             ), "binary <");
11537             result += Verify.Eval(() => TestBinaryOpRelation(d => !(null <= d)), "binary <=");
11538             result += Verify.Eval(() => TestBinaryOp(d => d & null, "&"), "binary &");
11539             result += Verify.Eval(() => TestBinaryOp(d => null | d, "|"), "binary |");
11540             // "null & null" will get error CS0034: Operator '&' is ambiguous on operands of type '<null>' and '<null>'
11541             // but "ni & null" will get null
11542             result += Verify.Eval(() => TestResultIsNull(d =>
11543             {
11544                 int? ni1 = null;
11545                 int? ni = ni1 ^ null;
11546                 return ni ^ d;
11547             }
11548 
11549             ), "binary ^");
11550             return result;
11551         }
11552 
TestBinaryOp(Func<dynamic, dynamic> exp, string op)11553         private static bool TestBinaryOp(Func<dynamic, dynamic> exp, string op)
11554         {
11555             dynamic d = null;
11556             try
11557             {
11558                 if (exp(d) != null)
11559                     return false;
11560             }
11561             catch (RuntimeBinderException e)
11562             {
11563                 if (ErrorVerifier.Verify(ErrorMessageId.AmbigBinaryOps, e.Message, op, ErrorVerifier.GetErrorElement(ErrorElementId.NULL), ErrorVerifier.GetErrorElement(ErrorElementId.NULL)))
11564                     return true;
11565             }
11566 
11567             return false;
11568         }
11569 
TestResultIsNull(Func<dynamic, dynamic> exp)11570         private static bool TestResultIsNull(Func<dynamic, dynamic> exp)
11571         {
11572             dynamic d = null;
11573             if (exp(d) != null)
11574                 return false;
11575             return true;
11576         }
11577 
TestBinaryOpRelation(Func<dynamic, dynamic> exp)11578         private static bool TestBinaryOpRelation(Func<dynamic, dynamic> exp)
11579         {
11580             dynamic d = null;
11581             return exp(d);
11582         }
11583     }
11584     //</Code>
11585 }
11586 
11587 
11588 
11589 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate019.operate019
11590 {
11591     using ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.common.common;
11592     // <Title>Other operators with both operand null</Title>
11593     // <Description>Conditional logical, conditional, compound</Description>
11594     // <RelatedBugs></RelatedBugs>
11595     // <Expects Status=success></Expects>
11596     // <Code>
11597 #pragma warning disable 0458 // expression always null warning
11598 
11599 #pragma warning disable 0464 // Comparing with null of type 'int?' always produces 'false'
11600 
11601     using System;
11602     using Microsoft.CSharp.RuntimeBinder;
11603 
11604     public class Test
11605     {
11606         [Fact]
DynamicCSharpRunTest()11607         public static void DynamicCSharpRunTest()
11608         {
11609             Assert.Equal(0, MainMethod());
11610         }
11611 
MainMethod()11612         public static int MainMethod()
11613         {
11614             int result = 0;
11615             result += Verify.Eval(() => TestBinaryOp(d => d += null, "+="), "compound +=");
11616             result += Verify.Eval(() => TestResultIsNull(d => d -= (null - null)), "compound -=");
11617             result += Verify.Eval(() => TestResultIsNull(d =>
11618             {
11619                 dynamic d2 = null * null;
11620                 return d *= d2;
11621             }
11622 
11623             ), "compound *=");
11624             result += Verify.Eval(() => TestResultIsNull(d =>
11625             {
11626                 int? ni = null / null;
11627                 return d /= ni;
11628             }
11629 
11630             ), "compound /=");
11631             result += Verify.Eval(() => TestResultIsNull(d => d %= null), "compound %=");
11632             result += Verify.Eval(() => TestResultIsNull(d => d <<= (null << null)), "compound <<=");
11633             result += Verify.Eval(() => TestResultIsNull(d =>
11634             {
11635                 int? ni = null >> null;
11636                 return d >>= ni;
11637             }
11638 
11639             ), "compound >>=");
11640             result += Verify.Eval(() => TestBinaryOp(d => d &= null, "&="), "compound &=");
11641             result += Verify.Eval(() => TestBinaryOp(d =>
11642             {
11643                 dynamic d2 = null;
11644                 return d |= d2;
11645             }
11646 
11647             , "|="), "compound |=");
11648             result += Verify.Eval(() => TestResultIsNull(d =>
11649             {
11650                 int? ni1 = null;
11651                 int? ni = ni1 ^ null;
11652                 return d ^= ni;
11653             }
11654 
11655             ), "compound ^=");
11656             result += Verify.Eval(() => TestConditionalLogicalOpWithFirstIsNull(d => d && null), "binary && with first is null");
11657             result += Verify.Eval(() => TestConditionalLogicalOpWithFirstIsNull(d => d || null), "binary || with first is null");
11658             result += Verify.Eval(() => TestConditionalLogicalOpWithFirstIsNull(d => d ? d : null), "conditional ?: with first is null");
11659             result += Verify.Eval(() => TestResultIsNull(d => true && d), "binary && with second is null");
11660             result += Verify.Eval(() => TestResultIsNull(d => false || d), "binary || with second is null");
11661             result += Verify.Eval(() => TestResultIsNull(d => true ? d : null), "conditional ?: with second and third are null");
11662             result += Verify.Eval(() => TestResultIsNull(d =>
11663             {
11664                 int? ni = null;
11665                 return true ? ni : d;
11666             }
11667 
11668             ), "conditional ?: with second and third are null");
11669             result += Verify.Eval(() => TestResultIsNull(d =>
11670             {
11671                 dynamic d2 = null;
11672                 return false ? d2 : d;
11673             }
11674 
11675             ), "conditional ?: with second and third are null");
11676             return result;
11677         }
11678 
TestBinaryOp(Func<dynamic, dynamic> exp, string op)11679         private static bool TestBinaryOp(Func<dynamic, dynamic> exp, string op)
11680         {
11681             dynamic d = null;
11682             try
11683             {
11684                 if (exp(d) != null)
11685                     return false;
11686             }
11687             catch (RuntimeBinderException e)
11688             {
11689                 if (ErrorVerifier.Verify(ErrorMessageId.AmbigBinaryOps, e.Message, op, ErrorVerifier.GetErrorElement(ErrorElementId.NULL), ErrorVerifier.GetErrorElement(ErrorElementId.NULL)))
11690                     return true;
11691             }
11692 
11693             return false;
11694         }
11695 
TestResultIsNull(Func<dynamic, dynamic> exp)11696         private static bool TestResultIsNull(Func<dynamic, dynamic> exp)
11697         {
11698             dynamic d = null;
11699             if (exp(d) != null)
11700                 return false;
11701             return true;
11702         }
11703 
TestConditionalLogicalOpWithFirstIsNull(Func<dynamic, dynamic> exp)11704         private static bool TestConditionalLogicalOpWithFirstIsNull(Func<dynamic, dynamic> exp)
11705         {
11706             dynamic d = null;
11707             try
11708             {
11709                 if (exp(d) != null)
11710                     return false;
11711             }
11712             catch (RuntimeBinderException e)
11713             {
11714                 if (ErrorVerifier.Verify(ErrorMessageId.ValueCantBeNull, e.Message, "bool"))
11715                     return true;
11716             }
11717 
11718             return false;
11719         }
11720     }
11721     //</Code>
11722 }
11723 
11724 
11725 
11726 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate020.operate020
11727 {
11728     // <Title>Regression test</Title>
11729     // <Description></Description>
11730     // <RelatedBugs></RelatedBugs>
11731     // <Expects Status=success></Expects>
11732     // <Code>
11733 
11734     public class Test
11735     {
11736         [Fact]
DynamicCSharpRunTest()11737         public static void DynamicCSharpRunTest()
11738         {
11739             Assert.Equal(0, MainMethod(null));
11740         }
11741 
MainMethod(string[] ars)11742         public static int MainMethod(string[] ars)
11743         {
11744             C c = new C();
11745             c[M()] -= 3;
11746             return (C.Hit - 4);
11747         }
11748 
M()11749         public static int M()
11750         {
11751             C.Hit = C.Hit + 5;
11752             return 0;
11753         }
11754     }
11755 
11756     public class C
11757     {
11758         public static int Hit = 1;
11759         public dynamic this[object o]
11760         {
11761             get
11762             {
11763                 C.Hit = C.Hit * 2;
11764                 return 1;
11765             }
11766 
11767             set
11768             {
11769                 C.Hit = C.Hit / 3;
11770             }
11771         }
11772     }
11773     //</Code>
11774 }
11775 
11776 
11777 
11778 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate021.operate021
11779 {
11780     // <Title>Regression test</Title>
11781     // <Description></Description>
11782     // <RelatedBugs></RelatedBugs>
11783     // <Expects Status=success></Expects>
11784     // <Code>
11785     public class A
11786     {
operator int(A x)11787         public static implicit operator int (A x)
11788         {
11789             return 1;
11790         }
11791 
operator A(int x)11792         public static implicit operator A(int x)
11793         {
11794             return new A();
11795         }
11796 
11797         [Fact]
DynamicCSharpRunTest()11798         public static void DynamicCSharpRunTest()
11799         {
11800             Assert.Equal(0, MainMethod());
11801         }
11802 
MainMethod()11803         public static int MainMethod()
11804         {
11805             var a = new A();
11806             a++;
11807             dynamic b = new A();
11808             try
11809             {
11810                 b++;
11811             }
11812             catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
11813             {
11814                 if (ErrorVerifier.Verify(ErrorMessageId.NoExplicitConv, e.Message, "int", "A"))
11815                     return 0;
11816             }
11817 
11818             return 1;
11819         }
11820     }
11821     //</Code>
11822 }
11823 
11824 
11825 
11826 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.operate022.operate022
11827 {
11828     // <Title>Regression test</Title>
11829     // <Description></Description>
11830     // <RelatedBugs></RelatedBugs>
11831     // <Expects Status=success></Expects>
11832     // <Code>
11833     //<Expects Status=warning>\(19,41\).*CS0168</Expects>
11834 
11835     public class A
11836     {
11837         [Fact]
DynamicCSharpRunTest()11838         public static void DynamicCSharpRunTest()
11839         {
11840             Assert.Equal(0, MainMethod());
11841         }
11842 
MainMethod()11843         public static int MainMethod()
11844         {
11845             dynamic a = new B<int>();
11846             try
11847             {
11848                 var c = a || a;
11849             }
11850             catch (System.ArgumentException e)
11851             {
11852                 return 0;
11853             }
11854 
11855             return 1;
11856         }
11857     }
11858 
11859     public class B<T>
11860     {
operator |(B<T> x, B<T> y)11861         public static B<string> operator |(B<T> x, B<T> y)
11862         {
11863             return null;
11864         }
11865 
operator true(B<T> x)11866         public static bool operator true(B<T> x)
11867         {
11868             return false;
11869         }
11870 
operator false(B<T> x)11871         public static bool operator false(B<T> x)
11872         {
11873             return false;
11874         }
11875     }
11876     //</Code>
11877 }
11878 
11879 
11880 
11881 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.literal001.literal001
11882 {
11883     // <Title>Dynamic method call with literal parameter</Title>
11884     // <Description> </Description>
11885     // <RelatedBugs></RelatedBugs>
11886     //<Expects Status=success></Expects>
11887     // <Code>
11888 
11889     public class Test
11890     {
Method1(byte b)11891         public byte Method1(byte b)
11892         {
11893             return byte.MaxValue;
11894         }
11895 
Method2(short b)11896         public short Method2(short b)
11897         {
11898             return 0;
11899         }
11900 
Method3(ushort b)11901         public ushort Method3(ushort b)
11902         {
11903             return ushort.MinValue;
11904         }
11905 
11906         [Fact]
DynamicCSharpRunTest()11907         public static void DynamicCSharpRunTest()
11908         {
11909             Assert.Equal(0, MainMethod());
11910         }
11911 
MainMethod()11912         public static int MainMethod()
11913         {
11914             dynamic d = new Test();
11915             bool ret = (byte.MaxValue == d.Method1(0));
11916             ret &= (0 == d.Method2(0));
11917             ret &= (ushort.MinValue == d.Method3(0));
11918             return ret ? 0 : 1;
11919         }
11920     }
11921     // </Code>
11922 }
11923 
11924 
11925 
11926 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.nullable001.nullable001
11927 {
11928     // <Title>Nullable and dynamic</Title>
11929     // <Description>
11930     // </Description>
11931     // <RelatedBugs></RelatedBugs>
11932     //<Expects Status=success></Expects>
11933     // <Code>
11934     public class D
11935     {
11936         public ulong? ulnull;
11937         public decimal? denull;
11938     }
11939 
11940     public class Program
11941     {
11942         [Fact]
DynamicCSharpRunTest()11943         public static void DynamicCSharpRunTest()
11944         {
11945             Assert.Equal(0, MainMethod(null));
11946         }
11947 
MainMethod(string[] args)11948         public static int MainMethod(string[] args)
11949         {
11950             dynamic d2 = new D();
11951             d2.ulnull = 3;
11952             if (d2.ulnull != 3)
11953                 return 1;
11954             d2.denull = 3m;
11955             if (d2.denull != 3m)
11956                 return 1;
11957             return 0;
11958         }
11959     }
11960     // </Code>
11961 }
11962 
11963 
11964 
11965 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.nullable002.nullable002
11966 {
11967     // <Title>Nullable and dynamic</Title>
11968     // <Description>
11969     // </Description>
11970     // <RelatedBugs></RelatedBugs>
11971     //<Expects Status=success></Expects>
11972     // <Code>
11973     public class D
11974     {
11975         public int? inull;
11976     }
11977 
11978     public class Program
11979     {
11980         public static int Status = 0;
11981         [Fact]
DynamicCSharpRunTest()11982         public static void DynamicCSharpRunTest()
11983         {
11984             Assert.Equal(0, MainMethod());
11985         }
11986 
MainMethod()11987         public static int MainMethod()
11988         {
11989             dynamic d2 = new D();
11990             d2.inull = 3;
11991             if (d2.inull != 3)
11992                 return 1;
11993             d2.inull = null;
11994             if (d2.inull != null)
11995                 return 1;
11996             return Program.Status;
11997         }
11998     }
11999     // </Code>
12000 }
12001 
12002 
12003 
12004 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.nullable003.nullable003
12005 {
12006     // <Title>Nullable and dynamic</Title>
12007     // <Description>
12008     // </Description>
12009     // <RelatedBugs></RelatedBugs>
12010     //<Expects Status=success></Expects>
12011     // <Code>
12012     public class D
12013     {
12014         public int? inull;
12015     }
12016 
12017     public class Program
12018     {
12019         public static int Status = 0;
12020         [Fact]
DynamicCSharpRunTest()12021         public static void DynamicCSharpRunTest()
12022         {
12023             Assert.Equal(0, MainMethod());
12024         }
12025 
MainMethod()12026         public static int MainMethod()
12027         {
12028             dynamic d2 = new D();
12029             d2.inull = 3;
12030             if (d2.inull != 3)
12031                 return 1;
12032             d2.inull = null;
12033             if (d2.inull != null)
12034                 return 1;
12035             return Program.Status;
12036         }
12037     }
12038     // </Code>
12039 }
12040 
12041 
12042 
12043 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.field001.field001
12044 {
12045     // <Title>Dynamic static fields</Title>
12046     // <Description>
12047     // </Description>
12048     // <RelatedBugs></RelatedBugs>
12049     // <Expects Status=success></Expects>
12050     // <Code>
12051 
12052     public class Test
12053     {
12054         public static dynamic c1 = 4;
12055         public static dynamic c2 = 4;
12056         public dynamic c3 = 4;
12057         public dynamic c4 = 4;
12058         [Fact]
DynamicCSharpRunTest()12059         public static void DynamicCSharpRunTest()
12060         {
12061             Assert.Equal(0, MainMethod());
12062         }
12063 
MainMethod()12064         public static int MainMethod()
12065         {
12066             int rez = 0;
12067             Test.c1 += (Test.c1 + Test.c2); //this does not work
12068             if (Test.c1 == 12)
12069                 rez++;
12070             dynamic d = new Test();
12071             d.c3 += (d.c3 + d.c4);
12072             if (d.c3 == 12)
12073                 rez++;
12074             return rez == 2 ? 0 : 1;
12075         }
12076     }
12077     // </Code>
12078 }
12079 
12080 
12081 
12082 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.field002.field002
12083 {
12084     // <Title>Dynamic static fields</Title>
12085     // <Description>
12086     // </Description>
12087     // <RelatedBugs></RelatedBugs>
12088     // <Expects Status=success></Expects>
12089     // <Code>
12090 
12091     public class P
12092     {
12093         public dynamic i = 0;
Foo()12094         public void Foo()
12095         {
12096             ++i;
12097         }
12098 
Bar()12099         public void Bar()
12100         {
12101             i++;
12102         }
12103 
12104         [Fact]
DynamicCSharpRunTest()12105         public static void DynamicCSharpRunTest()
12106         {
12107             Assert.Equal(0, MainMethod(null));
12108         }
12109 
MainMethod(string[] args)12110         public static int MainMethod(string[] args)
12111         {
12112             int rez = 0;
12113             dynamic d = new P();
12114             d.Foo();
12115             if (d.i == 1)
12116                 rez++;
12117             d.Bar();
12118             if (d.i == 2)
12119                 rez++;
12120             return rez == 2 ? 0 : 1;
12121         }
12122     }
12123     // </Code>
12124 }
12125 
12126 
12127 
12128 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.date001.date001
12129 {
12130     // <Title>dynamic expression on DateTime.Add...</Title>
12131     // <Description>
12132     // </Description>
12133     // <RelatedBugs></RelatedBugs>
12134     // <Expects Status=success></Expects>
12135     // <Code>
12136     using System;
12137 
12138     public class VerTest
12139     {
12140         [Fact]
DynamicCSharpRunTest()12141         public static void DynamicCSharpRunTest()
12142         {
12143             Assert.Equal(0, MainMethod());
12144         }
12145 
MainMethod()12146         public static int MainMethod()
12147         {
12148             // Just to verify there is no assertion here
12149             dynamic d = 1;
12150             DateTime c = (new DateTime(2000, 1, 1)).AddDays(d);
12151             c = (new DateTime(2000, 1, 1)).AddHours(d);
12152             c = (new DateTime(2000, 1, 1)).AddSeconds(d);
12153             return 0;
12154         }
12155     }
12156     // </Code>
12157 }
12158 
12159 
12160 
12161 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.gettype01.gettype01
12162 {
12163     // <Title>GetType should not hide object.GetType</Title>
12164     // <Description>
12165     // </Description>
12166     // <RelatedBugs></RelatedBugs>
12167     //<Expects Status=success></Expects>
12168     // <Code>
12169     using System;
12170 
12171     public class Program
12172     {
12173         [Fact]
DynamicCSharpRunTest()12174         public static void DynamicCSharpRunTest()
12175         {
12176             Assert.Equal(0, MainMethod(null));
12177         }
12178 
MainMethod(string[] args)12179         public static int MainMethod(string[] args)
12180         {
12181             Type d = typeof(ValueType);
12182             return new Program().Method(d);
12183         }
12184 
Method(dynamic d)12185         public int Method(dynamic d)
12186         {
12187             return 0;
12188         }
12189     }
12190     // </Code>
12191 }
12192 
12193 
12194 
12195 namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.gettype02.gettype02
12196 {
12197     // <Title>GetType should not hide object.GetType</Title>
12198     // <Description>
12199     // </Description>
12200     // <RelatedBugs></RelatedBugs>
12201     //<Expects Status=success></Expects>
12202     // <Code>
12203     using System;
12204 
12205     public class Program
12206     {
12207         [Fact]
DynamicCSharpRunTest()12208         public static void DynamicCSharpRunTest()
12209         {
12210             Assert.Equal(0, MainMethod(null));
12211         }
12212 
MainMethod(string[] args)12213         public static int MainMethod(string[] args)
12214         {
12215             Type d = typeof(ValueType);
12216             dynamic dy = new Program();
12217             return dy.Method(d);
12218         }
12219 
Method(dynamic d)12220         public int Method(dynamic d)
12221         {
12222             return 0;
12223         }
12224     }
12225     // </Code>
12226 }
12227