Re: issue when converting C#.net code into vb.net

Re: issue when converting C#.net code into vb.net

am 31.01.2008 16:53:02 von Dhananjay

On Jan 29, 7:28 pm, "PhilTheGap" wrote:
> Hi Dhananjay,
>
> you can try with Lutz Rioeder's Reflector. Download this tool, compile your
> code to produce a DLL, load it into Reflector then export it with VB...
>
> Philippe


HI Philippe,

Thanks a lot for reply.
Here in i am providing my both code files , can you please see where
is the problem. I have tried to correct it but it was not
successful.can you please provide me correct complete code. The
problem is same which i mentioned you. It gives error on Anonymous
method(i.e; Delegate concept).In the last reply you told me to change
the signature of method.problem lies in MembershipUserODS file.
please have a look and try to correct the code.Thanks in advance.

================================MemebershipUserODS.vb file
============================================================ =
Imports Microsoft.VisualBasic
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

'''


''' Class Used to Select, Update, Insert and Delete
''' From the Microsoft ASP.NET Membership API
'''

'''
_
Public Class MembershipUserODS

'''
''' This insert method is the default insert method. It is
typically associated with
''' a detailview control for inserting new members.
'''

''' MembershipUser.UserName
''' MembershipUser.password
''' MembershipUser.IsApproved
''' MembershipUser.comment
''' MembershipUser.lastLockoutDate param>
''' MembershipUser.creationDate
''' MembershipUser.email
''' MembershipUser.lastActivityDate param>
''' MembershipUser.providerName
''' MembershipUser.isLockedOut
''' MembershipUser.lastLoginDate
''' MembershipUser.isOnline
''' MembershipUser.passwordQuestion param>
''' name="lastPasswordChangedDate">MembershipUser.lastPasswordCh angedDate param>
'''
_
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

'''
''' Takes as input the original username and the current username
'''

'''
'''
'''
_
Public Shared Sub Delete(ByVal UserName As String)
Membership.DeleteUser(UserName, True)
End Sub

'''
''' This update method is the default update as shown by the class
attribute.
'''
'''

''' MembershipUser.UserName
originally retrieved
''' MembershipUser.email
''' MembershipUser.isApproved
''' MembershipUser.comment
''' MembershipUser.password
''' MembershipUser.passwordAnswer param>
''' MembershipUser.lastActivityDate param>
''' MembershipUser.lastLoginDate
'''
_
Public 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 Is Nothing OrElse mu.Comment.CompareTo(comment) <> 0
Then
dirtyFlag = True
mu.Comment = comment
End If

If mu.Email Is 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

'''
''' This is just used to set the IsApproved status.
''' username is always passed in for searching purposes.
'''

''' Current UserName to Update
(primary key)
''' MembershipUser.isApproved
'''
_
Public 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

'''
''' Make a list of MembershipUserWrapper objects
'''

''' A List of type MembershipUserWrapper
'''
_
Public Shared Function GetMembers() As List(Of
MembershipUserWrapper)
Return GetMembers(True, True, Nothing, Nothing)
End Function

'''
''' Make a list of MembershipUserWrapper objects by current sort
'''

''' Whicfh Column to perform the sort on param>
''' A List of type MembershipUserWrapper
'''
_
Public Shared Function GetMembers(ByVal sortData As String) As
List(Of MembershipUserWrapper)
' All Users, All approvalStatus
Return GetMembers(True, True, Nothing, sortData)
End Function

'''
''' returns all approved users by specified sort
'''

''' if true, return approved users param>
''' description of sort
''' A List of type MembershipUserWrapper
'''
_
Public Shared Function GetMembers(ByVal approvalStatus As Boolean,
ByVal sortData As String) As List(Of MembershipUserWrapper)
If approvalStatus = True Then
Return GetMembers(True, False, Nothing, sortData)
Else
Return GetMembers(False, True, Nothing, sortData)
End If
End Function

'''
''' Return a collection of MembershipUserWrapper's based on criteria
passed in as parameters
'''

''' returns all users with
approval set to true
''' return all users with
approval set to false
''' return based on username (overrides
approval above)
''' sort parameter
''' Returns a Collection of Users (as recommended by
FxCop)

'''
_
Public Shared Function GetMembers(ByVal returnAllApprovedUsers As
Boolean, ByVal returnAllNotApprovedUsers As Boolean, ByVal
usernameToFind As String, ByVal sortData As String) As List(Of
MembershipUserWrapper)

Dim memberList As List(Of MembershipUserWrapper) = New List(Of
MembershipUserWrapper)()

' See if we are looking for just one user
If usernameToFind IsNot Nothing Then
Dim mu As MembershipUser = Membership.GetUser(usernameToFind)
If mu IsNot Nothing Then
Dim md As 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 New MembershipUserWrapper(mu)
memberList.Add(md)
End If
Next mu

If sortData Is 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(Of MembershipUserWrapper) = Nothing

Select Case sortDataBase
Case "UserName"
comparison = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod1)
Case "Email"
comparison = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod2)
Case "CreationDate"
comparison = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod3)
Case "IsApproved"
comparison = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod4)
Case "IsOnline"
comparison = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod5)
Case "LastLoginDate"
comparison = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod6)
Case Else
comparison = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod7)
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

Private Shared Function AnonymousMethod1(ByVal lhs As
MembershipUserWrapper, ByVal rhs As MembershipUserWrapper) As Integer
Return lhs.UserName.CompareTo(rhs.UserName)
End Function

Private Shared Function AnonymousMethod2(ByVal lhs As
MembershipUserWrapper, ByVal rhs As MembershipUserWrapper) As Integer
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 Shared Function AnonymousMethod3(ByVal lhs As
MembershipUserWrapper, ByVal rhs As MembershipUserWrapper) As Object
Return lhs.CreationDate.CompareTo(rhs.CreationDate)
End Function

Private Shared Function AnonymousMethod4(ByVal lhs As
MembershipUserWrapper, ByVal rhs As MembershipUserWrapper) As Object
Return lhs.IsApproved.CompareTo(rhs.IsApproved)
End Function

Private Shared Function AnonymousMethod5(ByVal lhs As
MembershipUserWrapper, ByVal rhs As MembershipUserWrapper) As Object
Return lhs.IsOnline.CompareTo(rhs.IsOnline)
End Function

Private Shared Function AnonymousMethod6(ByVal lhs As
MembershipUserWrapper, ByVal rhs As MembershipUserWrapper) As Object
Return lhs.LastLoginDate.CompareTo(rhs.LastLoginDate)
End Function

Private Shared Function AnonymousMethod7(ByVal lhs As
MembershipUserWrapper, ByVal rhs As MembershipUserWrapper) As Object
Return lhs.UserName.CompareTo(rhs.UserName)
End Function
End Class
End Namespace
===================================================end
file======================================================== ====


=================================MembershipUserWrapper.vb
file======================================================== =====
Imports Microsoft.VisualBasic

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.Generic
Imports System.ComponentModel


Namespace MembershipUtilities



'''
''' Summary description for MembershipUserWrapper
''' This class is inherited from MembershipUser
''' Using the sytax public class ClassName (..) :
base(initializers...) allows for calling the
''' contstructor of the base class. In this case MembershipUser.
'''

'''
Public Class MembershipUserWrapper
Inherits MembershipUser

'''
''' This constructor is used to create a MembershipUserWrapper
from a MembershipUser object. MembershipUser is a default type used
''' in the Membership API provided with ASP.NET 2.0
'''

''' MembershipUser object
Public Sub New(ByVal mu As MembershipUser)
MyBase.New(mu.ProviderName, mu.UserName,
mu.ProviderUserKey, mu.Email, mu.PasswordQuestion, mu.Comment, _
mu.IsApproved, mu.IsLockedOut, mu.CreationDate,
mu.LastLoginDate, mu.LastActivityDate, mu.LastPasswordChangedDate, _
mu.LastLockoutDate)
End Sub


'''
''' This calls the base class UserName property. It is here so
we can tag
''' this property as the primary key so that datakeynames
attribute gets set in the data control.
'''

'''
_
Public Overloads Overrides ReadOnly Property UserName() As
String
Get
Return MyBase.UserName
End Get
End Property



'''
''' This constructor is used to create a MembershipUserWrapper
from individual parameters values.
''' For details of what each parameter means, see the
Microsoft Membership class.
'''

''' Passes to MembershipUser.comment param>
''' Passes to
MembershipUser.creationDate
''' Passes to MembershipUser.email
''' Passes to
MembershipUser.isApproved
''' Passes to
MembershipUser.lastActivityDate
''' Passes to
MembershipUser.lastLoginDate
''' Passes to
MembershipUser.passwordQuestion
''' Passes to
MembershipUser.providerUserKey
''' Passes to MembershipUser.userName param>
''' Passes to
MembershipUser.lastLockoutDate
''' Passes to
MembershipUser.providerName
'''
Public Sub New(ByVal comment As String, ByVal creationDate As
DateTime, ByVal email As String, ByVal isApproved As Boolean, ByVal
lastActivityDate As DateTime, ByVal lastLoginDate As DateTime, _
ByVal passwordQuestion As String, ByVal providerUserKey As
Object, ByVal userName As String, ByVal lastLockoutDate As DateTime,
ByVal providerName As String)
' This calls a constructor of MembershipUser automatically
because of the base reference above
MyBase.New(providerName, userName, providerUserKey, email,
passwordQuestion, comment, _
isApproved, False, creationDate, lastLoginDate,
lastActivityDate, DateTime.Now, _
lastLockoutDate)
End Sub

End Class

End Namespace

=====================================end
file======================================================== ===============
please try to provide me the solution ASAP. Thanks!