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

Cnnversion error & differences between nuget output & website output #1066

Closed ciprian-s closed 6 months ago

ciprian-s commented 6 months ago

This is the code which I attempt to transform to C# is something basic like:

<DllImport("User32.dll")> 
Private Shared Function EnumWindows(Callback As EnumWindowProcess, lParam As IntPtr) As Boolean
End Function

The result of conversion via ICSharpCode.CodeConverter (v9.2.4.657) is shown below (which is not ideal):

[DllImport(\"User32.dll\")]
private static global::System.Boolean EnumWindows(EnumWindowProcess Callback, IntPtr lParam)
{
return default;
}

However, via the webpage ( https://icsharpcode.github.io/CodeConverter/ ) I get the expected response like:

[DllImport("User32.dll")]
private static extern bool EnumWindows(EnumWindowProcess Callback, IntPtr lParam);

Can you please educate me about what I'm doing wrong via the nuget or what should I do as extra steps in order to get the same output as in the webpage via the nuget package (for a standalone transformation)? Currently I'm planning to use mainly the nuget. Can you please elaborate more about what is used within the page that causes for the output to be different? Mainly asking since I see mentioned a version of the bottom of the page: Code Converter 9.2.4.0

Many thanks for your time!

GrahamTheCoder commented 6 months ago

What does your current consuming code look like? Did you start from what's in the web project here: https://github.com/icsharpcode/CodeConverter/blob/bc6b62af01aae5328c12c7266b38bc4321ea72ee/Web/WebConverter.cs#L26-L31

Most people find the web converter or VS extension cover their needs, I'd be interested in what you're aiming to do, and it may help me to point to how best to use the api

ciprian-s commented 6 months ago

Currently I'm looking at moving some old pieces of code to C# but without Visual Studio. Found what was missing (WithTypeReferences made the difference). Many thanks for a very prompt response!