473,387 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Trying to convert Csharp to Vb.net, have problem

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
1 1725
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Altramagnus | last post by:
I have a complicated Region object, which I need to draw the outline, but not fill How can I convert the Region object to GraphicsPath object? or How can I draw the outline of the Region object?
3
by: hunterb | last post by:
I have a file which has no BOM and contains mostly single byte chars. There are numerous double byte chars (Japanese) which appear throughout. I need to take the resulting Unicode and store it in a...
3
by: bull.enteract | last post by:
Ok, I start off with a bitmap image. I encode it as a jpeg and send it across the network and pick it up on the other end. Now I have the jpeg image on the other end as an arrray of bytes and I...
1
by: Tamir Khason | last post by:
Somebody knows how to convert Bounds to Point ??? Thnx
2
by: Aaron Prohaska | last post by:
Can anyone tell me how I can convert the following code to csharp? I'm having problems with this because it seems as though KeyChar.IsDigit doesn't exist in csharp. ...
3
by: Mike | last post by:
Hi, Does anyone know of reliable programs that convert C# to Java and viceversa? Thanks Mike
7
by: Dica | last post by:
i've used the sample code from msdn to create an encyption/decryption assembly as found here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/SecNetHT10.asp i'm...
1
by: dongxm | last post by:
Is there a function can convert "abc" to "\u0097\u0098\u0099" in dotnet(c#)
5
by: moondaddy | last post by:
How do I get the string representation of an int? for example int var1 = 2; string var2 = var1.ToString; I'm wanting var2 to be "2" I get the compile error: Error 1 Cannot convert...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.