Skip to content

Commit

Permalink
Issue icsharpcode#854: Add test for Handles cluase having different c…
Browse files Browse the repository at this point in the history
…ase for property with event, use semantic model to get official name of the property
  • Loading branch information
jrmoreno1 committed Mar 26, 2022
1 parent 1ecb146 commit bfa7259
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 3 deletions.
6 changes: 3 additions & 3 deletions CodeConverter/CSharp/HandledEventsAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ private async Task<bool> IsNeverWrittenOrOverriddenAsync(ISymbol symbol)
.SelectMany(mss => mss.HandlesClause.Events, (_, e) => {
var eventSymbol = semanticModel.GetSymbolInfo(e.EventMember).Symbol as IEventSymbol;
// TODO: Need to either use the semantic model containing the event symbol, or bundle up the Event member with the possible symbol here for later use (otherwise it's null)
return (CreateEventContainer(e.EventContainer), new EventDescriptor(e.EventMember, eventSymbol), HandlingMethod: methodSymbol);
return (CreateEventContainer(e.EventContainer, semanticModel), new EventDescriptor(e.EventMember, eventSymbol), HandlingMethod: methodSymbol);
});
}
private HandledEventsAnalysis.EventContainer CreateEventContainer(Microsoft.CodeAnalysis.VisualBasic.Syntax.EventContainerSyntax p)
private HandledEventsAnalysis.EventContainer CreateEventContainer(Microsoft.CodeAnalysis.VisualBasic.Syntax.EventContainerSyntax p, SemanticModel semanticModel)
{
switch (p) {
//For me, trying to use "MyClass" in a Handles expression is a syntax error. Events aren't overridable anyway so I'm not sure how this would get used.
Expand All @@ -106,7 +106,7 @@ private HandledEventsAnalysis.EventContainer CreateEventContainer(Microsoft.Code
case Microsoft.CodeAnalysis.VisualBasic.Syntax.KeywordEventContainerSyntax _:
return new HandledEventsAnalysis.EventContainer(HandledEventsAnalysis.EventContainerKind.This, null);
case Microsoft.CodeAnalysis.VisualBasic.Syntax.WithEventsEventContainerSyntax weecs:
return new HandledEventsAnalysis.EventContainer(HandledEventsAnalysis.EventContainerKind.Property, weecs.Identifier.Text);
return new HandledEventsAnalysis.EventContainer(HandledEventsAnalysis.EventContainerKind.Property, semanticModel.GetSymbolInfo(weecs).Symbol.Name);
case Microsoft.CodeAnalysis.VisualBasic.Syntax.WithEventsPropertyEventContainerSyntax wepecs:
return new HandledEventsAnalysis.EventContainer(HandledEventsAnalysis.EventContainerKind.Property, wepecs.Property.Identifier.Text);
default:
Expand Down
70 changes: 70 additions & 0 deletions Tests/VB/CaseSensitivityTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System.Threading.Tasks;

using ICSharpCode.CodeConverter.Tests.TestRunners;
using ICSharpCode.CodeConverter.VB;

using Xunit;

namespace ICSharpCode.CodeConverter.Tests.VB
{

public class CaseSensitivityTests : ConverterTestBase
{
[Fact]
public async Task HandlesWithDifferingCaseTestAsync()
{
await TestConversionVisualBasicToCSharpAsync(@"Public Class VBIsCaseInsensitive
Inherits System.Web.UI.Page
Private Sub btnOK_Click(sender As Object, e As System.EventArgs) Handles btnOK.Click
End Sub
End Class
Partial Public Class VBIsCaseInsensitive
Protected WithEvents btnOk As Global.System.Web.UI.WebControls.Button
End Class
",
@"using System;
using System.Runtime.CompilerServices;
public partial class VBIsCaseInsensitive : System.Web.UI.Page
{
private void btnOK_Click(object sender, EventArgs e)
{
}
}
public partial class VBIsCaseInsensitive
{
private System.Web.UI.WebControls.Button _btnOk;
protected virtual System.Web.UI.WebControls.Button btnOk
{
[MethodImpl(MethodImplOptions.Synchronized)]
get
{
return _btnOk;
}
[MethodImpl(MethodImplOptions.Synchronized)]
set
{
if (_btnOk != null)
{
_btnOk.Click -= btnOK_Click;
}
_btnOk = value;
if (_btnOk != null)
{
_btnOk.Click += btnOK_Click;
}
}
}
}", hasLineCommentConversionIssue: true /*Fields re-ordered*/);
}



}
}

0 comments on commit bfa7259

Please sign in to comment.