Skip to content

Commit bd97bd1

Browse files
Merge pull request #1183 from GrahamTheCoder/fix-vbnet-xor-operator-to-csharp-caret
Fix: Convert VB.Net 'Operator Xor' to C# 'operator ^'
2 parents 68299ab + 275df01 commit bd97bd1

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
1010

1111
### VB -> C#
1212

13+
* Xor operator overloads now converted [#1182](htts://github.com/icsharpcode/CodeConverter/issues/1182)
1314

1415
### C# -> VB
1516

CodeConverter/CSharp/SyntaxKindExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ public static SyntaxKind ConvertToken(this Microsoft.CodeAnalysis.VisualBasic.Sy
243243
return SyntaxKind.AmpersandToken;
244244
case Microsoft.CodeAnalysis.VisualBasic.SyntaxKind.OrKeyword:
245245
return SyntaxKind.BarToken;
246+
case Microsoft.CodeAnalysis.VisualBasic.SyntaxKind.XorKeyword:
247+
return SyntaxKind.CaretToken;
246248
//
247249
case Microsoft.CodeAnalysis.VisualBasic.SyntaxKind.AssemblyKeyword:
248250
return SyntaxKind.AssemblyKeyword;

Tests/CSharp/MemberTests/OperatorMemberTests.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,5 +190,32 @@ End Operator
190190
Assert.Contains("Public Shared Operator ^(i As Integer,", convertedCode);
191191
Assert.Contains("_failedMemberConversionMarker2", convertedCode);
192192
Assert.Contains("Public Shared Operator Like(s As String,", convertedCode);
193+
}
194+
195+
[Fact]
196+
197+
public async Task XorOperatorOverloadConversionAsync()
198+
199+
{
200+
201+
await TestConversionVisualBasicToCSharpAsync(
202+
203+
@"
204+
Public Class MyType
205+
Public Shared Operator Xor(left As MyType, right As MyType) As MyType
206+
Throw New Global.System.NotSupportedException(""Not supported"")
207+
End Operator
208+
End Class",
209+
210+
@"using System;
211+
212+
public partial class MyType
213+
{
214+
public static MyType operator ^(MyType left, MyType right)
215+
{
216+
throw new NotSupportedException(""Not supported"");
217+
}
218+
}");
219+
193220
}
194221
}

0 commit comments

Comments
 (0)