This project is read-only.

Purpose of FakeContext.GetTheEnumerator?

Dec 7, 2010 at 9:41 PM

I don't see what value method GetTheEnumerator on the FakeContext object has?

Dec 7, 2010 at 9:56 PM
Edited Dec 7, 2010 at 10:22 PM

It wouldn’t let me implement both interfaces with one method.



Dec 7, 2010 at 9:59 PM

In VB or in C#? I just removed the GetTheEnumerator method in my C# project and everything seems to compile just fine...

It's been a while since I've done VB, but I do remember there being some challenges like that. Let me know if the VB version is the one with the issue and I'll see if it can be fixed.

Dec 7, 2010 at 10:23 PM

Yeah, I believe it's the VB version. Can't implement two interfaces that expose the same method name.

Dec 7, 2010 at 10:55 PM

Let me make sure I understand the problem clearly. You have a custom interface that needs a GetEnumerator method, but another required interface also has it? What is that custom interface? Can the custom interface inherit from the provided interface instead? Or perhaps the code relying on the custom interface can easily cast the object to the provided interface when needed?

Dec 13, 2010 at 6:35 AM

It's in both the C# and version. Since I implement 2 interfaces explicitly with the same method call, I had to duplicate it.


Dec 13, 2010 at 3:09 PM

In C#, it's perfectly possible to implement two interfaces that have a method with the same name.You just have to explicitly implement the interfaces. They can call the same method that's either private or public to the class. The methods in the interfaces can either have the same or different return types.

I sent a small C# sample app to your e-mail that demonstrates the process. I am sure it is in VB too, it's just been too long since I've used VB for work like that. However, IIRC, if you use the Handles keyword with the method, you should be able to get it to work.

Again, when I get some time, I'll look into the VB alternative.

Dec 29, 2010 at 8:48 AM

Yes sir it is possible in C# but not in VB.NET. So I left it that way so it would be complete mirror of the code in both languages. :)

Dec 29, 2010 at 3:00 PM


It is possible in VB.NET as well, provided that the methods return the same value. You create one method that implements the interface and then specify a comma-separated Handles list, like this:

Public Interface Interface1

Function GetEnumerator() As Integer

End Interface

Public Interface Interface2

Function GetEnumerator() As Integer

End Interface

Public Class Class1
Implements Interface1Interface2

Public Function GetEnumerator() As Integer Implements Interface1.GetEnumerator, Interface2.GetEnumerator
Return Me.GetEnumerator()
End Function

End Class
Dec 29, 2010 at 4:36 PM
Edited Dec 29, 2010 at 4:37 PM

Thank you for pointing that out. However, it implements two different types, one regular, one generic, so you can't use the same method.

I've tried combining the two, with no luck.

		''' <summary>
		''' Gets the enumerator for the fake objectset
		''' </summary>
		''' <returns>IEnumerator(of T)</returns>
		Public Function GetEnumerator() As System.Collections.Generic.IEnumerator(Of T) Implements System.Collections.Generic.IEnumerable(Of T).GetEnumerator
			Return _Container.GetEnumerator()
		End Function

		''' <summary>
		''' Gets the enumerator for the fake objectset
		''' </summary>
		''' <returns>IEnumerator(of T)</returns>
		Public Function GetTheEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
			Return Me.GetEnumerator()
		End Function

Dec 29, 2010 at 10:15 PM

OK, that's the catch with VB.NET of course. I ignored that point when I made the VB sample. I agree with keeping the generated code in sync between both languages.