Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# -> VB: Extension Methods incorrect #1118

Open
zijianhuang opened this issue Jul 20, 2024 · 0 comments
Open

C# -> VB: Extension Methods incorrect #1118

zijianhuang opened this issue Jul 20, 2024 · 0 comments
Labels
C# -> VB Specific to C# -> VB conversion

Comments

@zijianhuang
Copy link

Input code

	public static class ResponseMessageExtensions
	{
		public static void EnsureSuccessStatusCodeEx(this HttpResponseMessage responseMessage)
		{
			if (!responseMessage.IsSuccessStatusCode)
			{
				var responseText = responseMessage.Content.ReadAsStringAsync().Result;
				var contentType = responseMessage.Content.Headers.ContentType;
				throw new WebApiRequestException(responseMessage.ReasonPhrase, responseMessage.StatusCode, responseText, responseMessage.Headers, contentType);
			}
		}
	}

Erroneous output

Imports System.Runtime.CompilerServices

Public Module ResponseMessageExtensions
    <Extension()>
    Public Sub EnsureSuccessStatusCodeEx(Me responseMessage As HttpResponseMessage)
        If Not responseMessage.IsSuccessStatusCode Then
            Dim responseText = responseMessage.Content.ReadAsStringAsync().Result
            Dim contentType = responseMessage.Content.Headers.ContentType
            Throw New WebApiRequestException(responseMessage.ReasonPhrase, responseMessage.StatusCode, responseText, responseMessage.Headers, contentType)
        End If
    End Sub
End Module

Expected output

    Module ResponseMessageExtensions
        <Extension()>
        Public Sub EnsureSuccessStatusCodeEx(ByVal _responseMessage As HttpResponseMessage)
            If Not _responseMessage.IsSuccessStatusCode Then
                Dim responseText = _responseMessage.Content.ReadAsStringAsync().Result
                Dim contentType = _responseMessage.Content.Headers.ContentType
                Throw New WebApiRequestException(_responseMessage.ReasonPhrase, _responseMessage.StatusCode, responseText, _responseMessage.Headers, contentType)
            End If
        End Sub
    End Module

According to: https://learn.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/procedures/extension-methods

I am using https://icsharpcode.github.io/CodeConverter/ as of today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C# -> VB Specific to C# -> VB conversion
Projects
None yet
Development

No branches or pull requests

1 participant