By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,296 Members | 1,446 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,296 IT Pros & Developers. It's quick & easy.

Trying to convert Csharp to Vb.net, have problem

P: n/a
I am trying to sort the membership list of the membership provider for
ASP.NET
the code has retrieved the list and now we need to sort it by a parameter if
it was passed. So in C# the code is.
Comparison<MembershipUserWrappercomparer = null;

switch (sortDataBase)

{

case "UserName":

comparer = new Comparison<MembershipUserWrapper>(

delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)

{

return lhs.UserName.CompareTo(rhs.UserName);

}

);

break;

case "Email":

comparer = new Comparison<MembershipUserWrapper>(

delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)

{

if (lhs.Email == null | rhs.Email == null)

{

return 0;

}

else

{

return lhs.Email.CompareTo(rhs.Email);

}

}

);

break;

case "CreationDate":

comparer = new Comparison<MembershipUserWrapper>(

delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)

{

return lhs.CreationDate.CompareTo(rhs.CreationDate);

}

);

break;

case "IsApproved":

comparer = new Comparison<MembershipUserWrapper>(

delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)

{

return lhs.IsApproved.CompareTo(rhs.IsApproved);

}

);

break;

case "IsOnline":

comparer = new Comparison<MembershipUserWrapper>(

delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)

{

return lhs.IsOnline.CompareTo(rhs.IsOnline);

}

);

break;

case "LastLoginDate":

comparer = new Comparison<MembershipUserWrapper>(

delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)

{

return lhs.LastLoginDate.CompareTo(rhs.LastLoginDate);

}

);

break;

default:

comparer = new Comparison<MembershipUserWrapper>(

delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)

{

return lhs.UserName.CompareTo(rhs.UserName);

}

);

break;

}

I used a tool to convert to vb and came up with

Dim comparer As Comparison(Of MembershipUserWrapper) = Nothing

Select Case sortDataBase

Case "UserName"

comparer = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod1)

Case "Email"

comparer = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod2)

Case "CreationDate"

comparer = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod3)

Case "IsApproved"

comparer = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod4)

Case "IsOnline"

comparer = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod5)

Case "LastLoginDate"

comparer = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod6)

Case Else

comparer = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod7)

End Select

The function ends here so that the approppriate above code line can call the
annonymousmethod it wants and these are

Private Function AnonymousMethod1(ByVal lhs As MembershipUserWrapper, ByVal
rhs As MembershipUserWrapper) As Object

Return lhs.UserName.CompareTo(rhs.UserName)

End Function

Private Function AnonymousMethod2(ByVal lhs As MembershipUserWrapper, ByVal
rhs As MembershipUserWrapper) As Object

If lhs.Email Is Nothing Or rhs.Email Is Nothing Then

Return 0

Else

Return lhs.Email.CompareTo(rhs.Email)

End If

End Function

Private Function AnonymousMethod3(ByVal lhs As MembershipUserWrapper, ByVal
rhs As MembershipUserWrapper) As Object

Return lhs.CreationDate.CompareTo(rhs.CreationDate)

End Function

Private Function AnonymousMethod4(ByVal lhs As MembershipUserWrapper, ByVal
rhs As MembershipUserWrapper) As Object

Return lhs.IsApproved.CompareTo(rhs.IsApproved)

End Function

Private Function AnonymousMethod5(ByVal lhs As MembershipUserWrapper, ByVal
rhs As MembershipUserWrapper) As Object

Return lhs.IsOnline.CompareTo(rhs.IsOnline)

End Function

Private Function AnonymousMethod6(ByVal lhs As MembershipUserWrapper, ByVal
rhs As MembershipUserWrapper) As Object

Return lhs.LastLoginDate.CompareTo(rhs.LastLoginDate)

End Function

Private Function AnonymousMethod7(ByVal lhs As MembershipUserWrapper, ByVal
rhs As MembershipUserWrapper) As Object

Return lhs.UserName.CompareTo(rhs.UserName)

End Function

But this does not work - I get a warning message in the IDE Object does not
have the same signature as delegate.

Can anyone tell me how to fix this?

I would keep the C# since it works but it means I would have to writre all
my other classes in the App_Code folder in C# also It seems you can't mix C#
and VB in that folder.

Any help in resolving this problem would be greatly appreciated.

Bob


May 6 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Change the method return types to the appropriate delegate type.
It looks like you've used Instant VB to do the conversion, but in cases
where Instant VB cannot determine the return type, it uses 'Object', which of
course will need to be changed (we'll add a 'todo' comment for these cases in
the next build).
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
C++ to C# Converter: converts C++ to C#
Instant C++: converts C# or VB to C++/CLI
"Robert Dufour" wrote:
I am trying to sort the membership list of the membership provider for
ASP.NET
the code has retrieved the list and now we need to sort it by a parameter if
it was passed. So in C# the code is.
Comparison<MembershipUserWrappercomparer = null;

switch (sortDataBase)

{

case "UserName":

comparer = new Comparison<MembershipUserWrapper>(

delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)

{

return lhs.UserName.CompareTo(rhs.UserName);

}

);

break;

case "Email":

comparer = new Comparison<MembershipUserWrapper>(

delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)

{

if (lhs.Email == null | rhs.Email == null)

{

return 0;

}

else

{

return lhs.Email.CompareTo(rhs.Email);

}

}

);

break;

case "CreationDate":

comparer = new Comparison<MembershipUserWrapper>(

delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)

{

return lhs.CreationDate.CompareTo(rhs.CreationDate);

}

);

break;

case "IsApproved":

comparer = new Comparison<MembershipUserWrapper>(

delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)

{

return lhs.IsApproved.CompareTo(rhs.IsApproved);

}

);

break;

case "IsOnline":

comparer = new Comparison<MembershipUserWrapper>(

delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)

{

return lhs.IsOnline.CompareTo(rhs.IsOnline);

}

);

break;

case "LastLoginDate":

comparer = new Comparison<MembershipUserWrapper>(

delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)

{

return lhs.LastLoginDate.CompareTo(rhs.LastLoginDate);

}

);

break;

default:

comparer = new Comparison<MembershipUserWrapper>(

delegate(MembershipUserWrapper lhs, MembershipUserWrapper rhs)

{

return lhs.UserName.CompareTo(rhs.UserName);

}

);

break;

}

I used a tool to convert to vb and came up with

Dim comparer As Comparison(Of MembershipUserWrapper) = Nothing

Select Case sortDataBase

Case "UserName"

comparer = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod1)

Case "Email"

comparer = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod2)

Case "CreationDate"

comparer = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod3)

Case "IsApproved"

comparer = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod4)

Case "IsOnline"

comparer = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod5)

Case "LastLoginDate"

comparer = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod6)

Case Else

comparer = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod7)

End Select

The function ends here so that the approppriate above code line can call the
annonymousmethod it wants and these are

Private Function AnonymousMethod1(ByVal lhs As MembershipUserWrapper, ByVal
rhs As MembershipUserWrapper) As Object

Return lhs.UserName.CompareTo(rhs.UserName)

End Function

Private Function AnonymousMethod2(ByVal lhs As MembershipUserWrapper, ByVal
rhs As MembershipUserWrapper) As Object

If lhs.Email Is Nothing Or rhs.Email Is Nothing Then

Return 0

Else

Return lhs.Email.CompareTo(rhs.Email)

End If

End Function

Private Function AnonymousMethod3(ByVal lhs As MembershipUserWrapper, ByVal
rhs As MembershipUserWrapper) As Object

Return lhs.CreationDate.CompareTo(rhs.CreationDate)

End Function

Private Function AnonymousMethod4(ByVal lhs As MembershipUserWrapper, ByVal
rhs As MembershipUserWrapper) As Object

Return lhs.IsApproved.CompareTo(rhs.IsApproved)

End Function

Private Function AnonymousMethod5(ByVal lhs As MembershipUserWrapper, ByVal
rhs As MembershipUserWrapper) As Object

Return lhs.IsOnline.CompareTo(rhs.IsOnline)

End Function

Private Function AnonymousMethod6(ByVal lhs As MembershipUserWrapper, ByVal
rhs As MembershipUserWrapper) As Object

Return lhs.LastLoginDate.CompareTo(rhs.LastLoginDate)

End Function

Private Function AnonymousMethod7(ByVal lhs As MembershipUserWrapper, ByVal
rhs As MembershipUserWrapper) As Object

Return lhs.UserName.CompareTo(rhs.UserName)

End Function

But this does not work - I get a warning message in the IDE Object does not
have the same signature as delegate.

Can anyone tell me how to fix this?

I would keep the C# since it works but it means I would have to writre all
my other classes in the App_Code folder in C# also It seems you can't mix C#
and VB in that folder.

Any help in resolving this problem would be greatly appreciated.

Bob


May 6 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.