Error on Key property after converting from C# to VB.NET

114 views Asked by At

I have converted the following C# code to VB.NET code via http://converter.telerik.com/

public static MessageBoxResult Show(string caption, string text, MessageBoxButton button, MessageBoxImage image)
{
    _messageBox = new WpfMessageBox { Label1 = { Content = caption }, Label2 = { Content = text } };
    return _result;
}

This is the converted VB.NET code.

Public Shared Function Show(caption As String, text As String, button As MessageBoxButton, image As MessageBoxImage) As MessageBoxResult
    _messageBox = New WpfMessageBox() With { _
        Key .Label1 = {Key .Content = caption}, _
        Key .Label2 = {Key .Content = text} _
    }
    Return _result
End Function

Here is the error:

Error

2

There are 2 answers

2
Ry- On BEST ANSWER

The converter seems to think there’s an anonymous type involved here, but there isn’t. Remove Key.

Public Shared Function Show(caption As String, text As String, button As MessageBoxButton, image As MessageBoxImage) As MessageBoxResult
    _messageBox = New WpfMessageBox()
    _messageBox.Label1.Content = caption
    _messageBox.Label2.Content = text
    Return _result
End Function
0
SLaks On

This is a bug in the converter.

The Key prefix is used for anonymous types to affect equality; it is not legal for typed object initializers.

Remove that.