paul1956 / CSharpToVB

New version of CSharpToVB converter
MIT License
25 stars 9 forks source link

Evaluate type param #42

Closed VBAndCs closed 4 years ago

VBAndCs commented 4 years ago

C#:

var activateInfo = propertiesToActivate[i];

VB:

Dim activateInfo As PropertyActivator(Of TContext) = propertiesToActivate(i)

No need to explicit declaration here. This is OK: Dim activateInfo = propertiesToActivate(i)

But if you have to mention the type, you should evaluate the type param, instead using TContext which is the raw generic declaration not a real type. In this context, TContext is evaluated to be ViewContext(). You need to use a valid sample to reproduce this case.

VBAndCs commented 4 years ago

Similar issue here: C#:

                foreach (var item in ViewLocationExpanderValues)
                {
                    hashCodeCombiner.Add(item.Key, StringComparer.Ordinal);
                    hashCodeCombiner.Add(item.Value, StringComparer.Ordinal);
                }

VB:

                For Each item As IEnumerable(Of KeyValuePair(Of String, String)) In ViewLocationExpanderValues
                    _hashCodeCombiner.Add(item.Key, StringComparer.Ordinal)
                    _hashCodeCombiner.Add(item.Value, StringComparer.Ordinal)
                Next

The item is of type KeyValuePair(Of String, String) not IEnumerable(Of KeyValuePair(Of String, String)), and you can avoid this but maintain inference:

                For Each item In ViewLocationExpanderValues
                    _hashCodeCombiner.Add(item.Key, StringComparer.Ordinal)
                    _hashCodeCombiner.Add(item.Value, StringComparer.Ordinal)
                Next
paul1956 commented 4 years ago

I am getting your desired results when I just convert the snippet. I need a more complete example to debug the issue. I try to avoid type inference when I know the type. The defaults for all my projects are Infer Off, Strict On, Explicit On.

VBAndCs commented 4 years ago

You should stick with the original c# code. Inference makes the code shorter and cleaner so more readable. Besides, you write the full qualified names srating with system. Save your self the truple and keep inferencxe. C# and vb are idintical in this aspect.

paul1956 commented 4 years ago

I now support user setting of Option Infer, I may look at using this for source generation in the future. But it is not high priority.

paul1956 commented 4 years ago

I now allow the user to specify the options included in the converted code so you can set whatever you want and the converter will include your selections. @VBAndCs if you still have an issue open a new report with enough source to reproduce.