Hi All.
I have been converting a C# to VB.NET Web Project and I have one last
issue to contend with.
I have included relevant code below and an explanation of the error..
Public Function LoadMenuFromFil e(ByVal filePath As String) As
MenuDataSet
Dim cacheKey As String = filePath
Dim ds As MenuDataSet = CType(Cache(cac heKey), MenuDataSet)
If ds Is Nothing Then
'bind the menu
Dim serializer As XmlSerializer = New
XmlSerializer(T ype.GetType(Men uDataSet))
***** error above line Type.GetType(Me nuDataSet) ******
The error is a compiler error stating that MenuDataSet is a type and
cannot be used as an expression.
MenuDataSet is a class as shown below:
Public Class MenuDataSet
Implements ICloneable
Public Sections() As MenuSection
'/ <summary>
'/ Merges the provided data set with this dataset placing the
sections before or after
'/ the existing data.
'/ </summary>
'/ <param name="ds">The data set to merge with.</param>
'/ <param name="opt">The location where to merge the provided
data.</param>
Public Sub Merge(ds As MenuDataSet, opt As MergeLocation)
'check for nulls
If ds.Sections Is Nothing OrElse ds.Sections.Len gth = 0 Then
Return
End If
'check for nulls
If Sections Is Nothing OrElse Sections.Length = 0 Then
Sections = CType(ds.Sectio ns.Clone(), MenuSection())
Return
End If
'create new array
Dim newItems(Sectio ns.Length + ds.Sections.Len gth) As
MenuSection
Select Case opt
Case MergeLocation.B efore
Array.Copy(ds.S ections, 0, newItems, 0,
ds.Sections.Len gth)
Array.Copy(Sect ions, 0, newItems, ds.Sections.Len gth,
Sections.Length )
Case MergeLocation.A fter
Array.Copy(Sect ions, 0, newItems, 0, Sections.Length )
Array.Copy(ds.S ections, 0, newItems, Sections.Length ,
ds.Sections.Len gth)
End Select
Me.Sections = newItems
End Sub 'Merge
'/ <summary>
'/ Copy all data set elements
'/ </summary>
'/ <returns>A copy of this data set</returns>
Public Function Clone() As Object Implements System.ICloneab le.Clone
Dim ds As New MenuDataSet
If Not (Sections Is Nothing) Then
ds.Sections = New MenuSection(Sec tions.Length) {}
Dim i As Integer
While i < Sections.Length
ds.Sections(i) = CType(Sections( i).Clone(), MenuSection)
i += 1
End While
End If
Return ds
End Function 'Clone
End Class 'MenuDataSet
Has anyone got any ideas as to why it wont accept the class for the
GetType area?
Thanks,
Robert
I have been converting a C# to VB.NET Web Project and I have one last
issue to contend with.
I have included relevant code below and an explanation of the error..
Public Function LoadMenuFromFil e(ByVal filePath As String) As
MenuDataSet
Dim cacheKey As String = filePath
Dim ds As MenuDataSet = CType(Cache(cac heKey), MenuDataSet)
If ds Is Nothing Then
'bind the menu
Dim serializer As XmlSerializer = New
XmlSerializer(T ype.GetType(Men uDataSet))
***** error above line Type.GetType(Me nuDataSet) ******
The error is a compiler error stating that MenuDataSet is a type and
cannot be used as an expression.
MenuDataSet is a class as shown below:
Public Class MenuDataSet
Implements ICloneable
Public Sections() As MenuSection
'/ <summary>
'/ Merges the provided data set with this dataset placing the
sections before or after
'/ the existing data.
'/ </summary>
'/ <param name="ds">The data set to merge with.</param>
'/ <param name="opt">The location where to merge the provided
data.</param>
Public Sub Merge(ds As MenuDataSet, opt As MergeLocation)
'check for nulls
If ds.Sections Is Nothing OrElse ds.Sections.Len gth = 0 Then
Return
End If
'check for nulls
If Sections Is Nothing OrElse Sections.Length = 0 Then
Sections = CType(ds.Sectio ns.Clone(), MenuSection())
Return
End If
'create new array
Dim newItems(Sectio ns.Length + ds.Sections.Len gth) As
MenuSection
Select Case opt
Case MergeLocation.B efore
Array.Copy(ds.S ections, 0, newItems, 0,
ds.Sections.Len gth)
Array.Copy(Sect ions, 0, newItems, ds.Sections.Len gth,
Sections.Length )
Case MergeLocation.A fter
Array.Copy(Sect ions, 0, newItems, 0, Sections.Length )
Array.Copy(ds.S ections, 0, newItems, Sections.Length ,
ds.Sections.Len gth)
End Select
Me.Sections = newItems
End Sub 'Merge
'/ <summary>
'/ Copy all data set elements
'/ </summary>
'/ <returns>A copy of this data set</returns>
Public Function Clone() As Object Implements System.ICloneab le.Clone
Dim ds As New MenuDataSet
If Not (Sections Is Nothing) Then
ds.Sections = New MenuSection(Sec tions.Length) {}
Dim i As Integer
While i < Sections.Length
ds.Sections(i) = CType(Sections( i).Clone(), MenuSection)
i += 1
End While
End If
Return ds
End Function 'Clone
End Class 'MenuDataSet
Has anyone got any ideas as to why it wont accept the class for the
GetType area?
Thanks,
Robert
Comment