Solved

Convert from C# to VB.net

Posted on 2013-01-18
4
384 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 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