473,287 Members | 1,960 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,287 software developers and data experts.

I am trying to convert a file from C# to VB.NET - need help.

Hello,
Here is the code snippet I got strucked at.
I am unable to convert the below line of code to its equavalent vb.net
code. could some one please help me with this?

[DataObjectMethod(DataObjectMethodType.Select, true)]
static public List<RoleData> GetRoles()
{
return GetRoles(null, false);
}
Thanks
-L

Apr 28 '06 #1
5 3745
Hello Friends,
Thanks for the timely help. I have one more problem here

I am trying to convert the C# code snippet to

case "CreationDate":
comparison = new Comparison<MembershipUserWrapper>(
delegate(MembershipUserWrapper lhs,
MembershipUserWrapper rhs)
{
return
lhs.CreationDate.CompareTo(rhs.CreationDate);
}
);

to its equivalent vb.net and the tools give me the

Case "CreationDate"
comparison = New Comparison(delegate, MembershipUserWrapper,
lhs, MembershipUserWrapper, rhs)
Return lhs.CreationDate.CompareTo(rhs.CreationDate)

But when I pasted the code in my VS.NET it complains about the word
"delegate" in the line

"comparison = New Comparison(delegate, MembershipUserWrapper, lhs,
MembershipUserWrapper, rhs)"

and when I mouse hover it says "Expression expected"

Am I missing some thing here?
Thanks
-L

Apr 28 '06 #3
[xposted to vb group for confirmation]

Learner wrote:
Hello Friends,
Thanks for the timely help. I have one more problem here

I am trying to convert the C# code snippet to

case "CreationDate":
comparison = new Comparison<MembershipUserWrapper>(
delegate(MembershipUserWrapper lhs,
MembershipUserWrapper rhs)
{
return
lhs.CreationDate.CompareTo(rhs.CreationDate);
}
);

to its equivalent vb.net
VB.NET doesn't support anonymous delegates :( I think something like
this will do what you want:

' define a generic delegate type
'that takes two Ts and returns an integer
Delegate Function Comparison(Of T)(ByVal lhs As T, ByVal rhs As T)
As Integer

'our example class
Class MembershipUserWrapper

' a datetime attribute for it, wrapped in a property as usual
Private creationDateValue As DateTime
Public Property CreationDate() As DateTime
Get
Return creationDateValue
End Get
Set(ByVal value As DateTime)
creationDateValue = value
End Set
End Property

' the class method for comparing two instances of the class
Public Shared Function Compare(ByVal x As
MembershipUserWrapper, ByVal y As MembershipUserWrapper) As Integer
Return x.creationDateValue.CompareTo(y.creationDateValue)
End Function
End Class

Sub Main()
'the result of the comparison
Dim compar As Integer
'the two objects we are comparing
Dim lhs, rhs As MembershipUserWrapper

'create a comparison delegate that invokes
'the class' comparison method
'and pass this new delegate the two objects to compare
compar = (New Comparison(Of MembershipUserWrapper) _
(AddressOf MembershipUserWrapper.Compare)) _
(lhs, rhs)

End Sub
and the tools give me the


Looks like the tools get flummoxed by generics and/or dealing with
anonymous delegates.

If all the comparisons (not just this snippet) are being done like
this, I suspect there's something neater involving IComparable, but
maybe there's more to it.

--
Larry Lard
Replies to group please

Apr 28 '06 #4
Larry,

I have to go, so have to do it quick, VB has a lot of functions around the
day of week and others to manipulate with dates.

http://msdn2.microsoft.com/en-us/library/82yfs2zh.aspx

Cor

"Larry Lard" <la*******@hotmail.com> schreef in bericht
news:11*********************@e56g2000cwe.googlegro ups.com...
[xposted to vb group for confirmation]

Learner wrote:
Hello Friends,
Thanks for the timely help. I have one more problem here

I am trying to convert the C# code snippet to

case "CreationDate":
comparison = new Comparison<MembershipUserWrapper>(
delegate(MembershipUserWrapper lhs,
MembershipUserWrapper rhs)
{
return
lhs.CreationDate.CompareTo(rhs.CreationDate);
}
);

to its equivalent vb.net


VB.NET doesn't support anonymous delegates :( I think something like
this will do what you want:

' define a generic delegate type
'that takes two Ts and returns an integer
Delegate Function Comparison(Of T)(ByVal lhs As T, ByVal rhs As T)
As Integer

'our example class
Class MembershipUserWrapper

' a datetime attribute for it, wrapped in a property as usual
Private creationDateValue As DateTime
Public Property CreationDate() As DateTime
Get
Return creationDateValue
End Get
Set(ByVal value As DateTime)
creationDateValue = value
End Set
End Property

' the class method for comparing two instances of the class
Public Shared Function Compare(ByVal x As
MembershipUserWrapper, ByVal y As MembershipUserWrapper) As Integer
Return x.creationDateValue.CompareTo(y.creationDateValue)
End Function
End Class

Sub Main()
'the result of the comparison
Dim compar As Integer
'the two objects we are comparing
Dim lhs, rhs As MembershipUserWrapper

'create a comparison delegate that invokes
'the class' comparison method
'and pass this new delegate the two objects to compare
compar = (New Comparison(Of MembershipUserWrapper) _
(AddressOf MembershipUserWrapper.Compare)) _
(lhs, rhs)

End Sub
and the tools give me the


Looks like the tools get flummoxed by generics and/or dealing with
anonymous delegates.

If all the comparisons (not just this snippet) are being done like
this, I suspect there's something neater involving IComparable, but
maybe there's more to it.

--
Larry Lard
Replies to group please

Apr 28 '06 #5
Hello Larry,
Thanks for quick reply. I am trying to conver a bif C# file to its
equivalent VB.NET file.

I am a beginer in .net stuff. To give a you little back ground of what
I am doing here is trying to build a remote Admin page (similar to
ASP.NET configuration tool " Web Site Administration Tool " . So I was
searching the web and finally found one site
"http://peterkellner.net/archives/2006/01/09/24/" and the code is in C#
and it works pretty cool. Now, I am trying to convert that code in to
VB.NET.

Yes I am using convertors to convert the C# code to vb.net.

This is the file I am trying to convert from C# to VB.NET
************************************************** **C#
code*******************************************
/*
Copyright © 2005, Peter Kellner
All rights reserved.
http://peterkellner.net

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

- Neither Peter Kellner, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior written
permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Collections.ObjectModel;

namespace MembershipUtilities
{

/// <summary>
/// Class Used to Select, Update, Insert and Delete
/// From the Microsoft ASP.NET Membership API
/// </summary>
///
[DataObject(true)] // This attribute allows the ObjectDataSource
wizard to see this class
public class MembershipUserODS
{

/// <summary>
/// This insert method is the default insert method. It is
typically associated with
/// a detailview control for inserting new members.
/// </summary>
/// <param name="userName">MembershipUser.UserName</param>
/// <param name="password">MembershipUser.password</param>
/// <param name="isApproved">MembershipUser.IsApproved</param>
/// <param name="comment">MembershipUser.comment</param>
/// <param
name="lastLockoutDate">MembershipUser.lastLockoutD ate</param>
/// <param
name="creationDate">MembershipUser.creationDate</param>
/// <param name="email">MembershipUser.email</param>
/// <param
name="lastActivityDate">MembershipUser.lastActivit yDate</param>
/// <param
name="providerName">MembershipUser.providerName</param>
/// <param
name="isLockedOut">MembershipUser.isLockedOut</param>
/// <param
name="lastLoginDate">MembershipUser.lastLoginDate</param>
/// <param name="isOnline">MembershipUser.isOnline</param>
/// <param
name="passwordQuestion">MembershipUser.passwordQue stion</param>
/// <param
name="lastPasswordChangedDate">MembershipUser.last PasswordChangedDate</param>
///
[DataObjectMethod(DataObjectMethodType.Insert, true)]
static public void Insert(string userName, bool isApproved,
string comment, DateTime lastLockoutDate, DateTime
creationDate,
string email, DateTime lastActivityDate, string
providerName, bool isLockedOut,
DateTime lastLoginDate, bool isOnline, string
passwordQuestion,
DateTime lastPasswordChangedDate, string password, string
passwordAnswer)
{
// The incoming parameters, password and passwordAnswer are
not properties of the
// MembershipUser class. Membership has special member
functions to deal with these
// two special properties for security reasons. For this
reason, they do not appear
// in a datacontrol that is created with this user object.

//
// the only reason you may want to have defaults is so you
can build insert into your
// datacontrol. A better approach would be to either
follow the example shown in the
// Membership.asp page where the parameters are set
directly to the userobject, or not
// include "new" at all in your control and use the other
controls in the Membership API
// for creating new members. (CreateUserWizard, etc)
//
// It is recommended that you only enable the following
lines if you are sure of what you are doing

//if (password == null)
//{
// password = "pass0word";
//}

//if (passwordAnswer == null)
//{
// passwordAnswer = "Password Answer";
//}

MembershipCreateStatus status;
Membership.CreateUser(userName, password, email,
passwordQuestion, passwordAnswer, isApproved, out status);

if (status != MembershipCreateStatus.Success)
{
throw new ApplicationException(status.ToString());
}

MembershipUser mu = Membership.GetUser(userName);
mu.Comment = comment;
Membership.UpdateUser(mu);

}

/// <summary>
/// Takes as input the original username and the current
username
/// </summary>
/// <param name="providerUserKey"></param>
/// <param name="Original_providerUserKey"></param>
///
[DataObjectMethod(DataObjectMethodType.Delete, true)]
static public void Delete(string UserName)
{
Membership.DeleteUser(UserName, true);
}

/// <summary>
/// This update method is the default update as shown by the
class attribute.
///
/// </summary>
/// <param name="original_UserName">MembershipUser.UserName
originally retrieved</param>
/// <param name="email">MembershipUser.email</param>
/// <param name="isApproved">MembershipUser.isApproved</param>
/// <param name="comment">MembershipUser.comment</param>
/// <param name="password">MembershipUser.password</param>
/// <param
name="passwordAnswer">MembershipUser.passwordAnswe r</param>
/// <param
name="lastActivityDate">MembershipUser.lastActivit yDate</param>
/// <param
name="lastLoginDate">MembershipUser.lastLoginDate</param>
///
[DataObjectMethod(DataObjectMethodType.Update, true)]
static public void Update(string UserName, string email,
bool isApproved, string comment, DateTime
lastActivityDate, DateTime lastLoginDate)
{
bool dirtyFlag = false;

MembershipUser mu = Membership.GetUser(UserName);

if (mu.Comment == null || mu.Comment.CompareTo(comment) !=
0)
{
dirtyFlag = true;
mu.Comment = comment;
}

if (mu.Email == null || mu.Email.CompareTo(email) != 0)
{
dirtyFlag = true;
mu.Email = email;
}

if (mu.IsApproved != isApproved)
{
dirtyFlag = true;
mu.IsApproved = isApproved;
}

if (dirtyFlag == true)
{
Membership.UpdateUser(mu);
}
}

/// <summary>
/// This is just used to set the IsApproved status.
/// username is always passed in for searching purposes.
/// </summary>
/// <param name="original_username">Current UserName to Update
(primary key)</param>
/// <param name="isApproved">MembershipUser.isApproved</param>
///
[DataObjectMethod(DataObjectMethodType.Update, false)]
static public void Update(string Username, bool isApproved)
{
bool dirtyFlag = false;
MembershipUser mu = Membership.GetUser(Username);

if (mu.IsApproved != isApproved)
{
dirtyFlag = true;
mu.IsApproved = isApproved;
}
if (dirtyFlag == true)
{
Membership.UpdateUser(mu);
}
}

/// <summary>
/// Make a list of MembershipUserWrapper objects
/// </summary>
/// <returns>A List of type MembershipUserWrapper</returns>
///
[DataObjectMethod(DataObjectMethodType.Select, false)]
static public List<MembershipUserWrapper> GetMembers()
{
return GetMembers(true, true, null, null);
}

/// <summary>
/// Make a list of MembershipUserWrapper objects by current
sort
/// </summary>
/// <param name="sortData">Whicfh Column to perform the sort
on</param>
/// <returns>A List of type MembershipUserWrapper</returns>
///
[DataObjectMethod(DataObjectMethodType.Select, true)]
static public List<MembershipUserWrapper> GetMembers(string
sortData)
{
// All Users, All approvalStatus
return GetMembers(true, true, null, sortData);
}

/// <summary>
/// returns all approved users by specified sort
/// </summary>
/// <param name="approvalStatus">if true, return approved
users</param>
/// <param name="sortData">description of sort</param>
/// <returns>A List of type MembershipUserWrapper</returns>
///
[DataObjectMethod(DataObjectMethodType.Select, false)]
static public List<MembershipUserWrapper> GetMembers(bool
approvalStatus, string sortData)
{
if (approvalStatus == true)
{
return GetMembers(true, false, null, sortData);
}
else
{
return GetMembers(false, true, null, sortData);
}
}

/// <summary>
/// Return a collection of MembershipUserWrapper's based on
criteria passed in as parameters
/// </summary>
/// <param name="returnAllApprovedUsers">returns all users with
approval set to true</param>
/// <param name="returnAllNotApproviedUsers">return all users
with approval set to false</param>
/// <param name="usernameToFind">return based on username
(overrides approval above)</param>
/// <param name="sortData">sort parameter</param>
/// <returns>Returns a Collection of Users (as recommended by
FxCop)</returns>
///
[DataObjectMethod(DataObjectMethodType.Select, false)]
static public List<MembershipUserWrapper> GetMembers(bool
returnAllApprovedUsers, bool returnAllNotApprovedUsers,
string usernameToFind, string sortData)
{

List<MembershipUserWrapper> memberList = new
List<MembershipUserWrapper>();

// See if we are looking for just one user
if (usernameToFind != null)
{
MembershipUser mu = Membership.GetUser(usernameToFind);
if (mu != null)
{
MembershipUserWrapper md = new
MembershipUserWrapper(mu);
memberList.Add(md);
}
}
else
{
MembershipUserCollection muc =
Membership.GetAllUsers();
foreach (MembershipUser mu in muc)
{
if ((returnAllApprovedUsers == true &&
mu.IsApproved == true) ||
(returnAllNotApprovedUsers == true &&
mu.IsApproved == false))
{
MembershipUserWrapper md = new
MembershipUserWrapper(mu);
memberList.Add(md);
}
}

if (sortData == null)
{
sortData = "UserName";
}
if (sortData.Length == 0)
{
sortData = "UserName";
}

// Make a special version of sortData for the switch
statement so that whether or not the
// DESC is appended to the string sortData, it will
switch on the base of that string.
string sortDataBase = sortData; // init and assume
there is not DESC appended to sortData
string descString = " DESC";
if (sortData.EndsWith(descString))
{
sortDataBase = sortData.Substring(0,
sortData.Length - descString.Length);
}

Comparison<MembershipUserWrapper> comparison = null;

switch (sortDataBase)
{
case "UserName":
comparison = new
Comparison<MembershipUserWrapper>(
delegate(MembershipUserWrapper lhs,
MembershipUserWrapper rhs)
{
return
lhs.UserName.CompareTo(rhs.UserName);
}
);
break;
case "Email":
comparison = 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":
comparison = new
Comparison<MembershipUserWrapper>(
delegate(MembershipUserWrapper lhs,
MembershipUserWrapper rhs)
{
return
lhs.CreationDate.CompareTo(rhs.CreationDate);
}
);
break;
case "IsApproved":
comparison = new
Comparison<MembershipUserWrapper>(
delegate(MembershipUserWrapper lhs,
MembershipUserWrapper rhs)
{
return
lhs.IsApproved.CompareTo(rhs.IsApproved);
}
);
break;
case "IsOnline":
comparison = new
Comparison<MembershipUserWrapper>(
delegate(MembershipUserWrapper lhs,
MembershipUserWrapper rhs)
{
return
lhs.IsOnline.CompareTo(rhs.IsOnline);
}
);
break;
case "LastLoginDate":
comparison = new
Comparison<MembershipUserWrapper>(
delegate(MembershipUserWrapper lhs,
MembershipUserWrapper rhs)
{
return
lhs.LastLoginDate.CompareTo(rhs.LastLoginDate);
}
);
break;
default:
comparison = new
Comparison<MembershipUserWrapper>(
delegate(MembershipUserWrapper lhs,
MembershipUserWrapper rhs)
{
return
lhs.UserName.CompareTo(rhs.UserName);
}
);
break;
}
if (sortData.EndsWith("DESC"))
{
memberList.Sort(comparison);
memberList.Reverse();
}
else
{
memberList.Sort(comparison);
}

}

// FxCopy will give us a warning about returning a List
rather than a Collection.
// We could copy the data, but not worth the trouble.
return memberList;

}
}
}

************************************************** **End of C#
code***********************************

********************************************and the equivalent VB.NET
code ***********************
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.Collections
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Globalization
Imports System.Collections.ObjectModel

Namespace MembershipUtilities
' <summary>
' Class Used to Select, Update, Insert and Delete
' From the Microsoft ASP.NET Membership API
' </summary>
'
'Class This attribute allows the ObjectDataSource wizard to see
this class

<DataObject(True)> _
Public Class MembershipUserODS

' <summary>
' This insert method is the default insert method. It is
typically associated with
' a detailview control for inserting new members.
' </summary>
' <param name="userName">MembershipUser.UserName</param>
' <param name="password">MembershipUser.password</param>
' <param name="isApproved">MembershipUser.IsApproved</param>
' <param name="comment">MembershipUser.comment</param>
' <param
name="lastLockoutDate">MembershipUser.lastLockoutD ate</param>
' <param
name="creationDate">MembershipUser.creationDate</param>
' <param name="email">MembershipUser.email</param>
' <param
name="lastActivityDate">MembershipUser.lastActivit yDate</param>
' <param
name="providerName">MembershipUser.providerName</param>
' <param name="isLockedOut">MembershipUser.isLockedOut</param>
' <param
name="lastLoginDate">MembershipUser.lastLoginDate</param>
' <param name="isOnline">MembershipUser.isOnline</param>
' <param
name="passwordQuestion">MembershipUser.passwordQue stion</param>
' <param
name="lastPasswordChangedDate">MembershipUser.last PasswordChangedDate</param>
'
<DataObjectMethod(DataObjectMethodType.Insert, True)> _
Public Shared Sub Insert(ByVal userName As String, ByVal
isApproved As Boolean, ByVal comment As String, ByVal lastLockoutDate
As DateTime, ByVal creationDate As DateTime, ByVal email As String,
ByVal lastActivityDate As DateTime, ByVal providerName As String, ByVal
isLockedOut As Boolean, ByVal lastLoginDate As DateTime, ByVal isOnline
As Boolean, ByVal passwordQuestion As String, ByVal
lastPasswordChangedDate As DateTime, ByVal password As String, ByVal
passwordAnswer As String)
' The incoming parameters, password and passwordAnswer are
not properties of the
' MembershipUser class. Membership has special member
functions to deal with these
' two special properties for security reasons. For this
reason, they do not appear
' in a datacontrol that is created with this user object.
'
' the only reason you may want to have defaults is so you
can build insert into your
' datacontrol. A better approach would be to either follow
the example shown in the
' Membership.asp page where the parameters are set directly
to the userobject, or not
' include "new" at all in your control and use the other
controls in the Membership API
' for creating new members. (CreateUserWizard, etc)
'
' It is recommended that you only enable the following
lines if you are sure of what you are doing
'if (password == null)
'{
' password = "pass0word";
'}
'if (passwordAnswer == null)
'{
' passwordAnswer = "Password Answer";
'}
Dim status As MembershipCreateStatus
Membership.CreateUser(userName, password, email,
passwordQuestion, passwordAnswer, isApproved, status)
If (status <> MembershipCreateStatus.Success) Then
Throw New ApplicationException(status.ToString)
End If
Dim mu As MembershipUser = Membership.GetUser(userName)
mu.Comment = comment
Membership.UpdateUser(mu)
End Sub

' <summary>
' Takes as input the original username and the current username
' </summary>
' <param name="providerUserKey"></param>
' <param name="Original_providerUserKey"></param>
'
<DataObjectMethod(DataObjectMethodType.Delete, True)> _
Public Shared Sub Delete(ByVal UserName As String)
Membership.DeleteUser(UserName, True)
End Sub

' <summary>
' This update method is the default update as shown by the
class attribute.
'
' </summary>
' <param name="original_UserName">MembershipUser.UserName
originally retrieved</param>
' <param name="email">MembershipUser.email</param>
' <param name="isApproved">MembershipUser.isApproved</param>
' <param name="comment">MembershipUser.comment</param>
' <param name="password">MembershipUser.password</param>
' <param
name="passwordAnswer">MembershipUser.passwordAnswe r</param>
' <param
name="lastActivityDate">MembershipUser.lastActivit yDate</param>
' <param
name="lastLoginDate">MembershipUser.lastLoginDate</param>
'
<DataObjectMethod(DataObjectMethodType.Update, True)> _
Public Overloads Shared Sub Update(ByVal UserName As String,
ByVal email As String, ByVal isApproved As Boolean, ByVal comment As
String, ByVal lastActivityDate As DateTime, ByVal lastLoginDate As
DateTime)
Dim dirtyFlag As Boolean = False
Dim mu As MembershipUser = Membership.GetUser(UserName)
If ((mu.Comment = Nothing) _
OrElse (mu.Comment.CompareTo(comment) <> 0))
Then
dirtyFlag = True
mu.Comment = comment
End If
If ((mu.Email = Nothing) _
OrElse (mu.Email.CompareTo(email) <> 0)) Then
dirtyFlag = True
mu.Email = email
End If
If (mu.IsApproved <> isApproved) Then
dirtyFlag = True
mu.IsApproved = isApproved
End If
If (dirtyFlag = True) Then
Membership.UpdateUser(mu)
End If
End Sub

' <summary>
' This is just used to set the IsApproved status.
' username is always passed in for searching purposes.
' </summary>
' <param name="original_username">Current UserName to Update
(primary key)</param>
' <param name="isApproved">MembershipUser.isApproved</param>
'
<DataObjectMethod(DataObjectMethodType.Update, False)> _
Public Overloads Shared Sub Update(ByVal Username As String,
ByVal isApproved As Boolean)
Dim dirtyFlag As Boolean = False
Dim mu As MembershipUser = Membership.GetUser(Username)
If (mu.IsApproved <> isApproved) Then
dirtyFlag = True
mu.IsApproved = isApproved
End If
If (dirtyFlag = True) Then
Membership.UpdateUser(mu)
End If
End Sub

' <summary>
' Make a list of MembershipUserWrapper objects
' </summary>
' <returns>A List of type MembershipUserWrapper</returns>
'
<DataObjectMethod(DataObjectMethodType.Select, False)> _
Public Overloads Shared Function GetMembers() As List
Return GetMembers(True, True, Nothing, Nothing)
End Function

' <summary>
' Make a list of MembershipUserWrapper objects by current sort
' </summary>
' <param name="sortData">Whicfh Column to perform the sort
on</param>
' <returns>A List of type MembershipUserWrapper</returns>
'
<DataObjectMethod(DataObjectMethodType.Select, True)> _
Public Overloads Shared Function GetMembers(ByVal sortData As
String) As List
' All Users, All approvalStatus
Return GetMembers(True, True, Nothing, sortData)
End Function

' <summary>
' returns all approved users by specified sort
' </summary>
' <param name="approvalStatus">if true, return approved
users</param>
' <param name="sortData">description of sort</param>
' <returns>A List of type MembershipUserWrapper</returns>
'
<DataObjectMethod(DataObjectMethodType.Select, False)> _
Public Overloads Shared Function GetMembers(ByVal
approvalStatus As Boolean, ByVal sortData As String) As List
If (approvalStatus = True) Then
Return GetMembers(True, False, Nothing, sortData)
Else
Return GetMembers(False, True, Nothing, sortData)
End If
End Function

' <summary>
' Return a collection of MembershipUserWrapper's based on
criteria passed in as parameters
' </summary>
' <param name="returnAllApprovedUsers">returns all users with
approval set to true</param>
' <param name="returnAllNotApproviedUsers">return all users
with approval set to false</param>
' <param name="usernameToFind">return based on username
(overrides approval above)</param>
' <param name="sortData">sort parameter</param>
' <returns>Returns a Collection of Users (as recommended by
FxCop)</returns>
'
<DataObjectMethod(DataObjectMethodType.Select, False)> _
Public Overloads Shared Function GetMembers(ByVal
returnAllApprovedUsers As Boolean, ByVal returnAllNotApprovedUsers As
Boolean, ByVal usernameToFind As String, ByVal sortData As String) As
List
Dim memberList As List = New List
' See if we are looking for just one user
If (Not (usernameToFind) Is Nothing) Then
Dim mu As MembershipUser =
Membership.GetUser(usernameToFind)
If (Not (mu) Is Nothing) Then
Dim md As MembershipUserWrapper = New
MembershipUserWrapper(mu)
memberList.Add(md)
End If
Else
Dim muc As MembershipUserCollection =
Membership.GetAllUsers
For Each mu As MembershipUser In muc
If (((returnAllApprovedUsers = True) _
AndAlso (mu.IsApproved = True)) _
OrElse ((returnAllNotApprovedUsers =
True) _
AndAlso (mu.IsApproved = False))) Then
Dim md As MembershipUserWrapper = New
MembershipUserWrapper(mu)
memberList.Add(md)
End If
Next
If (sortData = Nothing) Then
sortData = "UserName"
End If
If (sortData.Length = 0) Then
sortData = "UserName"
End If
' Make a special version of sortData for the switch
statement so that whether or not the
' DESC is appended to the string sortData, it will
switch on the base of that string.
Dim sortDataBase As String = sortData
' init and assume there is not DESC appended to
sortData
Dim descString As String = " DESC"
If sortData.EndsWith(descString) Then
sortDataBase = sortData.Substring(0,
(sortData.Length - descString.Length))
End If
Dim comparison As Comparison = Nothing
Select Case (sortDataBase)
Case "UserName"
comparison = New Comparison(delegate,
MembershipUserWrapper, lhs, MembershipUserWrapper, rhs)
Return lhs.UserName.CompareTo(rhs.UserName)

Case "Email"
comparison = New Comparison(delegate,
MembershipUserWrapper, lhs, MembershipUserWrapper, rhs)
If ((lhs.Email = Nothing) _
Or (rhs.Email = Nothing)) Then
Return 0
Else
Return lhs.Email.CompareTo(rhs.Email)
End If

Case "CreationDate"
comparison = New Comparison(delegate,
MembershipUserWrapper, lhs, MembershipUserWrapper, rhs)
Return
lhs.CreationDate.CompareTo(rhs.CreationDate)

Case "IsApproved"
comparison = New Comparison(delegate,
MembershipUserWrapper, lhs, MembershipUserWrapper, rhs)
Return lhs.IsApproved.CompareTo(rhs.IsApproved)

Case "IsOnline"
comparison = New Comparison(delegate,
MembershipUserWrapper, lhs, MembershipUserWrapper, rhs)
Return lhs.IsOnline.CompareTo(rhs.IsOnline)

Case "LastLoginDate"
comparison = New Comparison(delegate,
MembershipUserWrapper, lhs, MembershipUserWrapper, rhs)
Return
lhs.LastLoginDate.CompareTo(rhs.LastLoginDate)

Case Else
comparison = New Comparison(delegate,
MembershipUserWrapper, lhs, MembershipUserWrapper, rhs)
Return lhs.UserName.CompareTo(rhs.UserName)

End Select
If sortData.EndsWith("DESC") Then
memberList.Sort(comparison)
memberList.Reverse()
Else
memberList.Sort(comparison)
End If
End If
' FxCopy will give us a warning about returning a List
rather than a Collection.
' We could copy the data, but not worth the trouble.
Return memberList
End Function

''****************************************This is your code
***************************************
'Delegate Function Comparison(Of T)(ByVal lhs As T, ByVal rhs
As T) As Integer
''our example class
'Class MembershipUserWrapper
' ' a datetime attribute for it, wrapped in a property as
usual
' Private creationDateValue As DateTime
' Public Property CreationDate() As DateTime
' Get
' Return creationDateValue
' End Get
' Set(ByVal value As DateTime)
' creationDateValue = value
' End Set
' End Property
' ' the class method for comparing two instances of the
class
' Public Shared Function Compare(ByVal x As
MembershipUserWrapper, ByVal y As MembershipUserWrapper) As Integer
' Return
x.creationDateValue.CompareTo(y.creationDateValue)
' End Function
'End Class
'Sub Main()
' 'the result of the comparison
' Dim compar As Integer
' 'the two objects we are comparing
' Dim lhs, rhs As MembershipUserWrapper
' 'create a comparison delegate that invokes
' 'the class' comparison method
' 'and pass this new delegate the two objects to compare
' compar = (New Comparison(Of MembershipUserWrapper) _
' (AddressOf MembershipUserWrapper.Compare)) _
' (lhs, rhs)
'End Sub
''************************************************ ******End of
your code*************************
End Class
End Namespace

********************************************End of VB.NET
code***************************************
Could you please help me with the right conversion.

Thanks
-L

Apr 28 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: meh | last post by:
Still have not been able to convert this. More importently.....Is this sample going about it the right way??? tia meh Here is the vb code.........I keep looking at older vb.net projects to...
1
by: Glenn Wilson | last post by:
I have been given a small project and was looking for some help. I need to convert doc file to tif documents, now I can do this by using a printer driver to do the change, but I need to be able to...
4
by: Garry Freemyer | last post by:
I'm trying to convert this macro to a c# function but I have a big problem. It's on the LEFT side of an assignment statement and I am extremely flustered over this one because I'm a little rusty...
25
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
5
by: bbb | last post by:
Hi, I need to convert XML files from Japanese encoding to UTF-8. I was using the following code: using ( FileStream fs = File.OpenRead(fromFile) ) { int fileSize = (int)fs.Length; int buffer...
9
by: Boris Yeltsin | last post by:
I use Master Pages, so I make use of URL rebasing through the ~ operator, like this in the <head>: <link runat="server" href="~/Root.master.css" media="screen" rel="stylesheet" type="text/css" />...
6
by: sweeet_addiction16 | last post by:
hello Im writin a code in c... can sum1 pls help me out in writing a c code to convert decimalnumber to hexadecimal number.The hexadecimal number generated has to be an unsigned long.
5
by: sonu | last post by:
hey good morning ...... how to convert a video file in .flv format in php for linux hosting......is there any package whis provide this facility . Can i use ffmpeg for linux hosting...
2
by: E11esar | last post by:
Hello there. I am going in bit of a circle with this matter; First some background: I am trying to upload the details of a CSV file into an Oracle table. I am using a StreamReader to copy a line...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.