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

VB -> C#: Conversion functions are not correctly translated #343

Closed
tverweij opened this issue Aug 2, 2019 · 2 comments

Comments

@tverweij
Copy link

commented Aug 2, 2019

Input code

Dim x As Integer = CInt(SomeObject)

Erroneous output

private int MyInt = System.Convert.ToInt32(SomeObject);

Expected output

private int MyInt = Microsoft.VisualBasic.CompilerServices.Conversions.ToGenericParameter<int>(SomeObject);;

Details

Product in use: web converter

Version in use: 7.0.0.0

This is not really convertable (as far as I know not documented anywhere), so the only way to convert this correctly is to use the Microsoft.VisualBasic.dll

@GrahamTheCoder

This comment has been minimized.

Copy link
Member

commented Aug 2, 2019

Thanks! Other test cases #327 and #331, I'll consolidate those issues into this more generally titled one

@GrahamTheCoder

This comment has been minimized.

Copy link
Member

commented Aug 3, 2019

If someone else wants to work on this, it's this method which determines the method invoked:

var systemDotConvert = ConvertType.FullName;
var convertMethods = semanticModel.Compilation.GetTypeByMetadataName(systemDotConvert).GetMembers().Where(m =>
m.Name.StartsWith("To", StringComparison.Ordinal) && m.GetParameters().Length == 1);
var methodsByType = convertMethods.Where(m => m.Name != nameof(Convert.ToBase64String))
.GroupBy(m => new { ReturnType = m.GetReturnType(), Name = $"{systemDotConvert}.{m.Name}" })
.ToDictionary(m => m.Key.ReturnType, m => m.Key.Name);
return methodsByType;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.