icsharpcode / CodeConverter

Convert code from C# to VB.NET and vice versa using Roslyn
https://icsharpcode.github.io/CodeConverter/
MIT License
795 stars 207 forks source link

VB -> C#: ASP.NET Inherits-attribute in aspx file does not get renamed properly #1088

Open WalterWigman-Iress opened 3 months ago

WalterWigman-Iress commented 3 months ago

VB.Net input code

In VB.net, a class can contain a method with the same name as the class. Lets call this class 'someclass'. In the aspx file, a reference is made to this file using 
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="SomeClass.aspx.vb" Inherits="SomeClass" ViewStateMode="Disabled" %>

with someclass.aspx.vb looking like this:
Public Class SomeClass
    Inherits BaseWebPage

    Private Sub SomeClass()
    'do nothing
    End Sub
End Class

Erroneous output

When converted to c#, the method name can't be the same as the classname, so the converter changes the classname, and appends 'Type', resulting in:
public class SomeClassType : BaseWebPage
{   
    private void SomeClass()
    {
        //do nothing
    }
}

However, the attribute Inherits="SomeClass" in the aspx file should also be changed into Inherits="SomeClassType", which does not happen currently. This won't be picked up during compilation, only at runtime, where the page will throw a 500 error, because the class-behind can't be found. 
Currently, the aspx-file is not touched at all: the reference to the vb-codehind stays unchanged (instead it should be changed to .cs, but this doesn't actually impact the application so just mentioning this as a side-note). 

Expected output

Must have: In the aspx-files, it should have it's Inherits-attribute changed if the classname changes.
Should have: In the aspx-files, change the CodeBehind value from .vb to .cs :)

Details