Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Convert from C# to VB.net

Posted on 2013-01-18
4
Medium Priority
?
392 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 75

Expert Comment

by:käµfm³d 👽
ID: 38792963
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
ID: 38793003
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 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 38793055
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
ID: 38793376
thanks
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month20 days, 23 hours left to enroll

810 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