-
Notifications
You must be signed in to change notification settings - Fork 235
Expand file tree
/
Copy pathMemberTests.cs
More file actions
1543 lines (1388 loc) · 42.5 KB
/
MemberTests.cs
File metadata and controls
1543 lines (1388 loc) · 42.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System.Threading.Tasks;
using ICSharpCode.CodeConverter.Tests.TestRunners;
using ICSharpCode.CodeConverter.VB;
using Xunit;
namespace ICSharpCode.CodeConverter.Tests.VB;
public class MemberTests : ConverterTestBase
{
[Fact]
public async Task TestPropertyWithModifierAsync()
{
await TestConversionCSharpToVisualBasicAsync(
@"class TestClass {
public string Text { get; private set; }
}", @"Friend Class TestClass
Private _Text As String
Public Property Text As String
Get
Return _Text
End Get
Private Set(value As String)
_Text = value
End Set
End Property
End Class
1 target compilation errors:
BC30451: '_Text' is not declared. It may be inaccessible due to its protection level.");
}
[Fact]
public async Task TestInferredPropertyInnerClassAsync(){
await TestConversionCSharpToVisualBasicAsync(
@"class TestClass {
class InnerClass {
public string Text { get; private set; }
}
}",
@"Friend Class TestClass
Friend Class InnerClass
Private _Text As String
Public Property Text As String
Get
Return _Text
End Get
Private Set(value As String)
_Text = value
End Set
End Property
End Class
End Class
1 target compilation errors:
BC30451: '_Text' is not declared. It may be inaccessible due to its protection level.");
}
[Fact]
public async Task TestProperty_StaticInferredAsync() {
await TestConversionCSharpToVisualBasicAsync(
@"class TestClass {
public static string Text { get; private set; };
public int Count { get; private set; };
}",
@"Friend Class TestClass
Private Shared _Text As String
Private _Count As Integer
Public Shared Property Text As String
Get
Return _Text
End Get
Private Set(value As String)
_Text = value
End Set
End Property
Public Property Count As Integer
Get
Return _Count
End Get
Private Set(value As Integer)
_Count = value
End Set
End Property
End Class
1 source compilation errors:
CS1597: Semicolon after method or accessor block is not valid
2 target compilation errors:
BC30451: '_Text' is not declared. It may be inaccessible due to its protection level.
BC30451: '_Count' is not declared. It may be inaccessible due to its protection level.");
}
[Fact]
public async Task TestProperty_StaticInferredInModuleAsync() {
await TestConversionCSharpToVisualBasicAsync(
@"static class TestClass {
public static string Text { get; private set; }
}",
@"Friend Module TestClass
Private _Text As String
Public Property Text As String
Get
Return _Text
End Get
Private Set(value As String)
_Text = value
End Set
End Property
End Module
1 target compilation errors:
BC30451: '_Text' is not declared. It may be inaccessible due to its protection level.");
}
[Fact]
public async Task TestFieldAsync()
{
await TestConversionCSharpToVisualBasicAsync(
@"class TestClass
{
const int answer = 42;
int value = 10;
readonly int v = 15;
}", @"Friend Class TestClass
Const answer As Integer = 42
Private value As Integer = 10
Private ReadOnly v As Integer = 15
End Class");
}
[Fact]
public async Task DoNotSimplifyArrayTypeInFieldDeclarationsAsync() {
await TestConversionCSharpToVisualBasicAsync(
@"class TestClass {
int[] answer = { 1, 2 };
}",
@"Friend Class TestClass
Private answer As Integer() = {1, 2}
End Class");
}
[Fact]
public async Task TestMethodWithCommentsAsync()
{
await TestConversionCSharpToVisualBasicAsync(
@"class TestClass
{
public void TestMethod<T, T2, T3>(out T argument, ref T2 argument2, T3 argument3) where T : class, new where T2 : struct
{
argument = null; //1
argument2 = default(T2); //2
argument3 = default(T3); //3
}
}", @"Imports System.Runtime.InteropServices
Friend Class TestClass
Public Sub TestMethod(Of T As {Class, New}, T2 As Structure, T3)(<Out> ByRef argument As T, ByRef argument2 As T2, argument3 As T3)
argument = Nothing '1
argument2 = Nothing '2
argument3 = Nothing '3
End Sub
End Class
2 source compilation errors:
CS1003: Syntax error, '(' expected
CS1026: ) expected");
}
[Fact]
public async Task TestMethodWithReturnTypeAsync()
{
await TestConversionCSharpToVisualBasicAsync(
@"class TestClass
{
public int TestMethod<T, T2, T3>(out T argument, ref T2 argument2, T3 argument3) where T : class, new where T2 : struct
{
return 0;
}
}", @"Imports System.Runtime.InteropServices
Friend Class TestClass
Public Function TestMethod(Of T As {Class, New}, T2 As Structure, T3)(<Out> ByRef argument As T, ByRef argument2 As T2, argument3 As T3) As Integer
Return 0
End Function
End Class
3 source compilation errors:
CS1003: Syntax error, '(' expected
CS1026: ) expected
CS0177: The out parameter 'argument' must be assigned to before control leaves the current method");
}
[Fact]
public async Task TestStaticMethodAsync()
{
await TestConversionCSharpToVisualBasicAsync(
@"class TestClass
{
public static void TestMethod<T, T2, T3>(out T argument, ref T2 argument2, T3 argument3) where T : class, new where T2 : struct
{
argument = null;
argument2 = default(T2);
argument3 = default(T3);
}
}", @"Imports System.Runtime.InteropServices
Friend Class TestClass
Public Shared Sub TestMethod(Of T As {Class, New}, T2 As Structure, T3)(<Out> ByRef argument As T, ByRef argument2 As T2, argument3 As T3)
argument = Nothing
argument2 = Nothing
argument3 = Nothing
End Sub
End Class
2 source compilation errors:
CS1003: Syntax error, '(' expected
CS1026: ) expected");
}
[Fact]
public async Task TestAbstractMethodAsync()
{
await TestConversionCSharpToVisualBasicAsync(
@"abstract class TestClass
{
public abstract void TestMethod();
}", @"Friend MustInherit Class TestClass
Public MustOverride Sub TestMethod()
End Class");
}
[Fact]
public async Task TestNewMethodIsOverloadsNotShadowsAsync()
{
await TestConversionCSharpToVisualBasicAsync(
@"class TestClass
{
public void TestMethod()
{
}
public void TestMethod(int i)
{
}
}
class TestSubclass : TestClass
{
public new void TestMethod()
{
TestMethod(3);
System.Console.WriteLine(""Shadowed implementation"");
}
}", @"Friend Class TestClass
Public Sub TestMethod()
End Sub
Public Sub TestMethod(i As Integer)
End Sub
End Class
Friend Class TestSubclass
Inherits TestClass
Public Overloads Sub TestMethod()
TestMethod(3)
System.Console.WriteLine(""Shadowed implementation"")
End Sub
End Class", conversionOptions: EmptyNamespaceOptionStrictOff);
}
[Fact]
public async Task OperatorOverloadsAsync()
{
// Note a couple map to the same thing in C# so occasionally the result won't compile. The user can manually decide what to do in such scenarios.
await TestConversionCSharpToVisualBasicAsync(@"public class AcmeClass
{
public static AcmeClass operator +(int i, AcmeClass ac)
{
return ac;
}
public static AcmeClass operator +(string s, AcmeClass ac)
{
return ac;
}
public static AcmeClass operator -(int i, AcmeClass ac)
{
return ac;
}
public static AcmeClass operator !(AcmeClass ac)
{
return ac;
}
public static AcmeClass operator *(int i, AcmeClass ac)
{
return ac;
}
public static AcmeClass operator /(int i, AcmeClass ac)
{
return ac;
}
public static AcmeClass operator %(string s, AcmeClass ac)
{
return ac;
}
public static AcmeClass operator <<(AcmeClass ac, int i)
{
return ac;
}
public static AcmeClass operator >>(AcmeClass ac, int i)
{
return ac;
}
public static AcmeClass operator ==(string s, AcmeClass ac)
{
return ac;
}
public static AcmeClass operator !=(string s, AcmeClass ac)
{
return ac;
}
public static AcmeClass operator <(string s, AcmeClass ac)
{
return ac;
}
public static AcmeClass operator >(string s, AcmeClass ac)
{
return ac;
}
public static AcmeClass operator <=(string s, AcmeClass ac)
{
return ac;
}
public static AcmeClass operator >=(string s, AcmeClass ac)
{
return ac;
}
public static AcmeClass operator &(string s, AcmeClass ac)
{
return ac;
}
public static AcmeClass operator |(string s, AcmeClass ac)
{
return ac;
}
}", @"Public Class AcmeClass
Public Shared Operator +(i As Integer, ac As AcmeClass) As AcmeClass
Return ac
End Operator
Public Shared Operator &(s As String, ac As AcmeClass) As AcmeClass
Return ac
End Operator
Public Shared Operator -(i As Integer, ac As AcmeClass) As AcmeClass
Return ac
End Operator
Public Shared Operator Not(ac As AcmeClass) As AcmeClass
Return ac
End Operator
Public Shared Operator *(i As Integer, ac As AcmeClass) As AcmeClass
Return ac
End Operator
Public Shared Operator /(i As Integer, ac As AcmeClass) As AcmeClass
Return ac
End Operator
Public Shared Operator Mod(s As String, ac As AcmeClass) As AcmeClass
Return ac
End Operator
Public Shared Operator <<(ac As AcmeClass, i As Integer) As AcmeClass
Return ac
End Operator
Public Shared Operator >>(ac As AcmeClass, i As Integer) As AcmeClass
Return ac
End Operator
Public Shared Operator =(s As String, ac As AcmeClass) As AcmeClass
Return ac
End Operator
Public Shared Operator <>(s As String, ac As AcmeClass) As AcmeClass
Return ac
End Operator
Public Shared Operator <(s As String, ac As AcmeClass) As AcmeClass
Return ac
End Operator
Public Shared Operator >(s As String, ac As AcmeClass) As AcmeClass
Return ac
End Operator
Public Shared Operator <=(s As String, ac As AcmeClass) As AcmeClass
Return ac
End Operator
Public Shared Operator >=(s As String, ac As AcmeClass) As AcmeClass
Return ac
End Operator
Public Shared Operator And(s As String, ac As AcmeClass) As AcmeClass
Return ac
End Operator
Public Shared Operator Or(s As String, ac As AcmeClass) As AcmeClass
Return ac
End Operator
End Class");
}
[Fact]
public async Task TestNarrowingWideningConversionOperatorAsync()
{
await TestConversionCSharpToVisualBasicAsync(@"
public partial class MyInt
{
public static explicit operator MyInt(int i)
{
return new MyInt();
}
public static implicit operator int(MyInt myInt)
{
return 1;
}
}", @"
Public Partial Class MyInt
Public Shared Narrowing Operator CType(i As Integer) As MyInt
Return New MyInt()
End Operator
Public Shared Widening Operator CType(myInt As MyInt) As Integer
Return 1
End Operator
End Class"
);
}
[Fact]
public async Task TestSealedMethodAsync()
{
await TestConversionCSharpToVisualBasicAsync(
@"class TestClass
{
public sealed void TestMethod<T, T2, T3>(out T argument, ref T2 argument2, T3 argument3) where T : class, new where T2 : struct
{
argument = null;
argument2 = default(T2);
argument3 = default(T3);
}
}", @"Imports System.Runtime.InteropServices
Friend Class TestClass
Public NotOverridable Sub TestMethod(Of T As {Class, New}, T2 As Structure, T3)(<Out> ByRef argument As T, ByRef argument2 As T2, argument3 As T3)
argument = Nothing
argument2 = Nothing
argument3 = Nothing
End Sub
End Class
3 source compilation errors:
CS1003: Syntax error, '(' expected
CS1026: ) expected
CS0238: 'TestClass.TestMethod<T, T2, T3>(out T, ref T2, T3)' cannot be sealed because it is not an override
1 target compilation errors:
BC31088: 'NotOverridable' cannot be specified for methods that do not override another method.");
}
[Fact]
public async Task TestExtensionMethodAsync()
{
await TestConversionCSharpToVisualBasicAsync(
@"using System;
static class TestClass
{
public static void TestMethod(this String str)
{
}
public static void TestMethod2Parameters(this String str, Action<string> _)
{
}
}", @"Imports System
Imports System.Runtime.CompilerServices
Friend Module TestClass
<Extension()>
Public Sub TestMethod(Me str As String)
End Sub
<Extension()>
Public Sub TestMethod2Parameters(Me str As String, __ As Action(Of String))
End Sub
End Module", conversionOptions: EmptyNamespaceOptionStrictOff);
}
[Fact]
public async Task TestExtensionMethodWithExistingImportAsync()
{
await TestConversionCSharpToVisualBasicAsync(
@"using System; //Gets simplified away
using System.Runtime.CompilerServices;
static class TestClass
{
public static void TestMethod(this String str)
{
}
}", @"Imports System.Runtime.CompilerServices
Friend Module TestClass
<Extension()>
Public Sub TestMethod(Me str As String)
End Sub
End Module");
}
[Fact]
public async Task TestPropertyAsync()
{
await TestConversionCSharpToVisualBasicAsync(
@"class TestClass
{
public int Test { get; set; }
public int Test2 {
get { return 0; }
}
int m_test3;
public int Test3 {
get { return this.m_test3; }
set { this.m_test3 = value; }
}
}", @"Friend Class TestClass
Public Property Test As Integer
Public ReadOnly Property Test2 As Integer
Get
Return 0
End Get
End Property
Private m_test3 As Integer
Public Property Test3 As Integer
Get
Return m_test3
End Get
Set(value As Integer)
m_test3 = value
End Set
End Property
End Class");
}
[Fact]
public async Task CaseConflict_PropertyAndField_EnsureOtherClassNotAffectedAsync() {
await TestConversionCSharpToVisualBasicAsync(
@"public class HasConflictingPropertyAndField {
int test;
public int Test {
get { return test; }
set { test = value; }
}
}
public class ShouldNotChange {
int test;
public int Test1 {
get { return test; }
set { test = value; }
}
}
",
@"Public Class HasConflictingPropertyAndField
Private testField As Integer
Public Property Test As Integer
Get
Return testField
End Get
Set(value As Integer)
testField = value
End Set
End Property
End Class
Public Class ShouldNotChange
Private test As Integer
Public Property Test1 As Integer
Get
Return test
End Get
Set(value As Integer)
test = value
End Set
End Property
End Class");
}
[Fact]
public async Task CaseConflict_ArgumentFieldAndMethodWithOverloadsAsync() {
await TestConversionCSharpToVisualBasicAsync(
@"public class HasConflictingMethodAndField {
public int HasConflictingParam(int test) {
this.teSt = test;
return test;
}
int teSt;
private int test() {
return 1;
}
public int Test() {
return test();
}
private int test(int arg) {
return arg;
}
public int Test(int arg) {
return test(arg);
}
}",
@"Public Class HasConflictingMethodAndField
Public Function HasConflictingParam(test As Integer) As Integer
teStField = test
Return test
End Function
Private teStField As Integer
Private Function testMethod() As Integer
Return 1
End Function
Public Function Test() As Integer
Return testMethod()
End Function
Private Function testMethod(arg As Integer) As Integer
Return arg
End Function
Public Function Test(arg As Integer) As Integer
Return testMethod(arg)
End Function
End Class");
}
[Fact]
public async Task CaseConflict_ArgumentFieldAndPropertyAsync() {
await TestConversionCSharpToVisualBasicAsync(
@"public class HasConflictingPropertyAndField {
public int HasConflictingParam(int test) {
this.test = test;
return test;
}
int test;
public int Test {
get { return test; }
set { test = value; }
}
}",
@"Public Class HasConflictingPropertyAndField
Public Function HasConflictingParam(test As Integer) As Integer
testField = test
Return test
End Function
Private testField As Integer
Public Property Test As Integer
Get
Return testField
End Get
Set(value As Integer)
testField = value
End Set
End Property
End Class");
}
[Fact]
public async Task CaseConflict_ArgumentPropertyAndFieldAsync() {
await TestConversionCSharpToVisualBasicAsync(
@"public class HasConflictingPropertyAndField {
int test;
public int Test {
get { return test; }
set { test = value; }
}
public int HasConflictingParam(int test) {
Test = test;
return test;
}
}",
@"Public Class HasConflictingPropertyAndField
Private testField As Integer
Public Property Test As Integer
Get
Return testField
End Get
Set(value As Integer)
testField = value
End Set
End Property
Public Function HasConflictingParam(test As Integer) As Integer
Me.Test = test
Return test
End Function
End Class");
}
[Fact]
public async Task CaseConflict_PartialClass_ArgumentFieldPropertyAndLocalInBothPartsAsync() {
await TestConversionCSharpToVisualBasicAsync(
@"public partial class HasConflictingPropertyAndField {
public int HasConflictingParam(int test) {
int TEST = 0;
this.test = test + TEST;
return test;
}
}
public partial class HasConflictingPropertyAndField {
int test;
public int Test {
get
{
int TEST = 0;
return test + TEST;
}
set { test = value; }
}
}",
@"Public Partial Class HasConflictingPropertyAndField
Public Function HasConflictingParam(test As Integer) As Integer
Dim lTEST = 0
testField = test + lTEST
Return test
End Function
End Class
Public Partial Class HasConflictingPropertyAndField
Private testField As Integer
Public Property Test As Integer
Get
Dim lTEST = 0
Return testField + lTEST
End Get
Set(value As Integer)
testField = value
End Set
End Property
End Class");
}
[Fact]
public async Task TestPropertyWithExpressionBodyAsync()
{
await TestConversionCSharpToVisualBasicAsync(
@"public class ConversionResult
{
private string _sourcePathOrNull;
public string SourcePathOrNull {
get => _sourcePathOrNull;
set => _sourcePathOrNull = string.IsNullOrWhiteSpace(value) ? null : value;
}
}", @"Public Class ConversionResult
Private _sourcePathOrNull As String
Public Property SourcePathOrNull As String
Get
Return _sourcePathOrNull
End Get
Set(value As String)
_sourcePathOrNull = If(String.IsNullOrWhiteSpace(value), Nothing, value)
End Set
End Property
End Class");
}
[Fact]
public async Task TestOmmittedAccessorsReplacedWithExpressionBodyAsync()
{
await TestConversionCSharpToVisualBasicAsync(
@"class MyFavColor
{
private string[] favColor => new string[] {""Red"", ""Green""};
public string this[int index] => favColor[index];
}
", @"Friend Class MyFavColor
Private ReadOnly Property favColor As String()
Get
Return New String() {""Red"", ""Green""}
End Get
End Property
Default Public ReadOnly Property Item(index As Integer) As String
Get
Return favColor(index)
End Get
End Property
End Class");
}
[Fact]
public async Task TestPropertyWithExpressionBodyThatCanBeStatementAsync()
{
await TestConversionCSharpToVisualBasicAsync(
@"using System;
public class ConversionResult
{
private int _num;
public string Num {
set => _num++;
}
public string Blanket {
set => throw new Exception();
}
}", @"Imports System
Public Class ConversionResult
Private _num As Integer
Public WriteOnly Property Num As String
Set(value As String)
_num += 1
End Set
End Property
Public WriteOnly Property Blanket As String
Set(value As String)
Throw New Exception()
End Set
End Property
End Class");
}
[Fact]
public async Task TestPropertyWithAttributeAsync()
{
await TestConversionCSharpToVisualBasicAsync(
@"class TestClass
{
[DatabaseGenerated(DatabaseGeneratedOption.None)]
int value { get; set; }
}", @"Friend Class TestClass
<DatabaseGenerated(DatabaseGeneratedOption.None)>
Private Property value As Integer
End Class
3 source compilation errors:
CS0246: The type or namespace name 'DatabaseGeneratedAttribute' could not be found (are you missing a using directive or an assembly reference?)
CS0246: The type or namespace name 'DatabaseGenerated' could not be found (are you missing a using directive or an assembly reference?)
CS0103: The name 'DatabaseGeneratedOption' does not exist in the current context
2 target compilation errors:
BC30002: Type 'DatabaseGenerated' is not defined.
BC30451: 'DatabaseGeneratedOption' is not declared. It may be inaccessible due to its protection level.
");
}
[Fact]
public async Task TestClassWithGlobalAttributeAsync()
{
await TestConversionCSharpToVisualBasicAsync(
@"[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources
{
}", @"
<Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute()>
Friend Class Resources
End Class
1 target compilation errors:
BC30002: Type 'Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute' is not defined.
");
}
[Fact]
public async Task TestConstructorAsync()
{
await TestConversionCSharpToVisualBasicAsync(
@"class TestClass<T, T2, T3> where T : class, new where T2 : struct
{
public TestClass(out T argument, ref T2 argument2, T3 argument3)
{
}
}", @"Imports System.Runtime.InteropServices
Friend Class TestClass(Of T As {Class, New}, T2 As Structure, T3)
Public Sub New(<Out> ByRef argument As T, ByRef argument2 As T2, argument3 As T3)
End Sub
End Class
3 source compilation errors:
CS1003: Syntax error, '(' expected
CS1026: ) expected
CS0177: The out parameter 'argument' must be assigned to before control leaves the current method");
}
[Fact]
public async Task TestStaticConstructorAsync()
{
await TestConversionCSharpToVisualBasicAsync(
@"static SurroundingClass()
{
}", @"Shared Sub New()
End Sub");
}
[Fact]
public async Task TestConstructorCallingBaseAsync()
{
await TestConversionCSharpToVisualBasicAsync(
@"public class MyBaseClass
{
public MyBaseClass(object o)
{
}
}
public sealed class MyClass
: MyBaseClass
{
public MyClass(object o)
: base(o)
{
}
}", @"Public Class MyBaseClass
Public Sub New(o As Object)
End Sub
End Class
Public NotInheritable Class [MyClass]
Inherits MyBaseClass
Public Sub New(o As Object)
MyBase.New(o)
End Sub
End Class");
}
[Fact]
public async Task TestDestructorAsync()
{
await TestConversionCSharpToVisualBasicAsync(
@"class TestClass
{
~TestClass()
{
}
}", @"Friend Class TestClass
Protected Overrides Sub Finalize()
End Sub
End Class");
}
[Fact]
public async Task TestExternDllImportAsync()
{
await TestConversionCSharpToVisualBasicAsync(
@"[DllImport(""kernel32.dll"", SetLastError = true)]
static extern IntPtr OpenProcess(AccessMask dwDesiredAccess, bool bInheritHandle, uint dwProcessId);",
@"<DllImport(""kernel32.dll"", SetLastError:=True)>
Private Shared Function OpenProcess(dwDesiredAccess As AccessMask, bInheritHandle As Boolean, dwProcessId As UInteger) As IntPtr
End Function
3 source compilation errors:
CS0246: The type or namespace name 'AccessMask' could not be found (are you missing a using directive or an assembly reference?)
CS0246: The type or namespace name 'DllImportAttribute' could not be found (are you missing a using directive or an assembly reference?)
CS0246: The type or namespace name 'DllImport' could not be found (are you missing a using directive or an assembly reference?)
1 target compilation errors:
BC30002: Type 'AccessMask' is not defined.");
}
[Fact]
public async Task TestEventAsync()
{
await TestConversionCSharpToVisualBasicAsync(
@"class TestClass
{
public event EventHandler MyEvent;
}", @"Friend Class TestClass
Public Event MyEvent As EventHandler
End Class
1 source compilation errors:
CS0246: The type or namespace name 'EventHandler' could not be found (are you missing a using directive or an assembly reference?)");
}
[Fact]
public async Task TestCustomEventAsync() {
await TestConversionCSharpToVisualBasicAsync(
@"using System;
class TestClass {
EventHandler backingField;