Solved

Convert from C# to VB.net

Posted on 2013-01-18
4
375 Views
Last Modified: 2013-01-18
Hello.  I ran this code through a converter but it failed :(

I don't understand the purpose of the square brackets in C#

Could someone convert it for me please?

[Table]
public class ToDoItem : INotifyPropertyChanged, INotifyPropertyChanging
{
// Define ID: private field, public property and database column.
private int _toDoItemId;

[Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
public int ToDoItemId
{
    get
    {
        return _toDoItemId;
    }
    set
    {
        if (_toDoItemId != value)
        {
            NotifyPropertyChanging("ToDoItemId");
            _toDoItemId = value;
            NotifyPropertyChanged("ToDoItemId");
        }
    }
}

// Define item name: private field, public property and database column.
private string _itemName;

[Column]
public string ItemName
{
    get
    {
        return _itemName;
    }
    set
    {
        if (_itemName != value)
        {
            NotifyPropertyChanging("ItemName");
            _itemName = value;
            NotifyPropertyChanged("ItemName");
        }
    }
}

// Define completion value: private field, public property and database column.
private bool _isComplete;

[Column]
public bool IsComplete
{
    get
    {
        return _isComplete;
    }
    set
    {
        if (_isComplete != value)
        {
            NotifyPropertyChanging("IsComplete");
            _isComplete = value;
            NotifyPropertyChanged("IsComplete");
        }
    }
}
// Version column aids update performance.
[Column(IsVersion = true)]
private Binary _version;

#region INotifyPropertyChanged Members

public event PropertyChangedEventHandler PropertyChanged;

// Used to notify the page that a data context property changed
private void NotifyPropertyChanged(string propertyName)
{
    if (PropertyChanged != null)
    {
        PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }
}

#endregion

#region INotifyPropertyChanging Members

public event PropertyChangingEventHandler PropertyChanging;

// Used to notify the data context that a data context property is about to change
private void NotifyPropertyChanging(string propertyName)
{
    if (PropertyChanging != null)
    {
        PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
    }
}

#endregion
}

Open in new window

0
Comment
Question by:Dodsworth
  • 2
  • 2
4 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
Square brackets (as used above) denote attributes. In VB.NET, you use angle brackets ( < > ) for attributes.

Does this work? If not, what line(s) are in error?

<Table> _
Public Class ToDoItem
    Implements INotifyPropertyChanged
    Implements INotifyPropertyChanging
    ' Define ID: private field, public property and database column.
    Private _toDoItemId As Integer

    <Column(IsPrimaryKey := True, IsDbGenerated := True, DbType := "INT NOT NULL Identity", CanBeNull := False, AutoSync := AutoSync.OnInsert)> _
    Public Property ToDoItemId() As Integer
        Get
            Return _toDoItemId
        End Get
        Set
            If _toDoItemId <> value Then
                NotifyPropertyChanging("ToDoItemId")
                _toDoItemId = value
                NotifyPropertyChanged("ToDoItemId")
            End If
        End Set
    End Property

    ' Define item name: private field, public property and database column.
    Private _itemName As String

    <Column> _
    Public Property ItemName() As String
        Get
            Return _itemName
        End Get
        Set
            If _itemName <> value Then
                NotifyPropertyChanging("ItemName")
                _itemName = value
                NotifyPropertyChanged("ItemName")
            End If
        End Set
    End Property

    ' Define completion value: private field, public property and database column.
    Private _isComplete As Boolean

    <Column> _
    Public Property IsComplete() As Boolean
        Get
            Return _isComplete
        End Get
        Set
            If _isComplete <> value Then
                NotifyPropertyChanging("IsComplete")
                _isComplete = value
                NotifyPropertyChanged("IsComplete")
            End If
        End Set
    End Property
    ' Version column aids update performance.
    <Column(IsVersion := True)> _
    Private _version As Binary

    #Region "INotifyPropertyChanged Members"

    Public Event PropertyChanged As PropertyChangedEventHandler

    ' Used to notify the page that a data context property changed
    Private Sub NotifyPropertyChanged(propertyName As String)
        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
    End Sub

    #End Region

    #Region "INotifyPropertyChanging Members"

    Public Event PropertyChanging As PropertyChangingEventHandler

    ' Used to notify the data context that a data context property is about to change
    Private Sub NotifyPropertyChanging(propertyName As String)
        RaiseEvent PropertyChanging(Me, New PropertyChangingEventArgs(propertyName))
    End Sub

    #End Region
End Class

'=======================================================
'Service provided by Telerik (www.telerik.com)
'Conversion powered by NRefactory.
'Twitter: @telerik, @toddanglin
'Facebook: facebook.com/telerik
'=======================================================

Open in new window

0
 
LVL 1

Author Comment

by:Dodsworth
Comment Utility
that's solved the square bracket problem


errors on

Implements INotifyPropertyChanged
Implements INotifyPropertyChanging

Error      1      Class 'ToDoItem' must implement 'Event PropertyChanged(sender As Object, e As PropertyChangedEventArgs)' for interface 'System.ComponentModel.INotifyPropertyChanged'.      C:\Users\maf\documents\visual studio 2010\Projects\BTDT\BTDT\MainPage.xaml.vb      55      20      BTDT
0
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
Change line 61 in my last snippet to:

Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged

Open in new window


...and line 72 to:

Public Event PropertyChanging As PropertyChangingEventHandler Implements INotifyPropertyChanging.PropertyChanging

Open in new window

0
 
LVL 1

Author Closing Comment

by:Dodsworth
Comment Utility
thanks
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now