R
Robert Dufour
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<MembershipUserWrapper> comparer = 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
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<MembershipUserWrapper> comparer = 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