VB to C# conversion. Implements
-
I am converting a class from VB to C# so that it can be compiled into the same assembly, but have run into something that I don't know how to handle. The class is a generic ObservableDictionary. My problem is that I don't know how to implement both System.Collections.Generic.IEnumerable.GetEnumerator and System.Collections.IEnumerable.GetEnumerator since both of them need an exposed function named GetEnumerator(). The VB code is as follows:
Public Function GetEnumerator()
As System.Collections.Generic.IEnumerator(
Of System.Collections.Generic.KeyValuePair(Of TKey, TValue))
Implements System.Collections.Generic.IEnumerable(
Of System.Collections.Generic.KeyValuePair(Of TKey, TValue)).GetEnumeratorReturn DirectCast(Dictionary, IDictionary).GetEnumerator()
End Function
Private Function GetEnumerator1()
As System.Collections.IEnumerator
Implements System.Collections.IEnumerable.GetEnumeratorReturn GetEnumerator()
End Function
It looks to me like the VB code is renaming the GetEnumerator function to GetEnumerator1 and explicitly mapping this back to the GetEnumerator function that is being implemented, but I have never seen anything like this in C#. Is this possible in C#?
-
I am converting a class from VB to C# so that it can be compiled into the same assembly, but have run into something that I don't know how to handle. The class is a generic ObservableDictionary. My problem is that I don't know how to implement both System.Collections.Generic.IEnumerable.GetEnumerator and System.Collections.IEnumerable.GetEnumerator since both of them need an exposed function named GetEnumerator(). The VB code is as follows:
Public Function GetEnumerator()
As System.Collections.Generic.IEnumerator(
Of System.Collections.Generic.KeyValuePair(Of TKey, TValue))
Implements System.Collections.Generic.IEnumerable(
Of System.Collections.Generic.KeyValuePair(Of TKey, TValue)).GetEnumeratorReturn DirectCast(Dictionary, IDictionary).GetEnumerator()
End Function
Private Function GetEnumerator1()
As System.Collections.IEnumerator
Implements System.Collections.IEnumerable.GetEnumeratorReturn GetEnumerator()
End Function
It looks to me like the VB code is renaming the GetEnumerator function to GetEnumerator1 and explicitly mapping this back to the GetEnumerator function that is being implemented, but I have never seen anything like this in C#. Is this possible in C#?
Yep. I was going to type it all out, but that's a lot of typing... Heh VB:
Public Function DoSomething() Implements A.B.C.DoSomething
End Function
C#:
public void A.B.C.DoSomething()
{
}EDIT: There's a shortcut, by the way... Right-click the interface in the class definition, and pick "Implement Interface Explicitly"
Proud to have finally moved to the A-Ark. Which one are you in? Author of Guardians of Xen (Sci-Fi/Fantasy novel)