The other post was mostly correct, but there were two mistakes: 1. the
constructor is not private and 2. the indexers should be named the standard
"Item".
Our Instant VB C# to VB converter produces:
<ListBindable(False)> _
Public Class CategoriesInfo : Inherits CollectionBase
Private Shared instance_Renamed As CategoriesInfo
' create the static instance of the class
Shared Sub New()
instance_Renamed = New CategoriesInfo()
End Sub
Public ReadOnly Default Property Item(ByVal index As Integer) As
CategoryInfo
Get
Return TryCast(List(index), CategoryInfo)
End Get
End Property
Public ReadOnly Default Property Item(ByVal name As String) As CategoryInfo
Get
For i As Integer = 0 To Count - 1
If name.ToUpper() = Me(i).Name.ToUpper() Then
Return Me(i)
End If
Next i
Return Nothing
End Get
End Property
' Register the category in the system
Public Shared Sub Add(ByVal name As String, ByVal imageIndex As Integer)
Dim item As CategoryInfo = New CategoryInfo(name, imageIndex)
instance_Renamed.List.Add(item)
End Sub
Public Shared Sub Add(ByVal name As String)
CategoriesInfo.Add(name, -1)
End Sub
Public Shared ReadOnly Property Instance() As CategoriesInfo
Get
Return instance_Renamed
End Get
End Property
End Class
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter
"Bob Roy" wrote:
Could someone help me translating the following C# code to VB? Is there
a different newsgroup where it would be better to post this?
[ListBindable(false)]
public class CategoriesInfo : CollectionBase {
static CategoriesInfo instance;
// create the static instance of the class
static CategoriesInfo() {
instance = new CategoriesInfo();
}
public CategoryInfo this[int index] { get { return List[index] as
CategoryInfo; } }
public CategoryInfo this[string name] {
get {
for(int i = 0; i < Count; i ++)
if(name.ToUpper() == this[i].Name.ToUpper())
return this[i];
return null;
}
}
// Register the category in the system
public static void Add(string name, int imageIndex) {
CategoryInfo item = new CategoryInfo(name, imageIndex);
instance.List.Add(item);
}
public static void Add(string name) {
CategoriesInfo.Add(name, -1);
}
public static CategoriesInfo Instance { get { return instance; } }
}
*** Sent via Developersdex http://www.developersdex.com ***