I see all you smart guys refer to the specs and I need to start referring to those more, I just was looking at some MSIL and noticed it was not calling any of the methods through the interface
What would you do if you just know that those methods are there?
Rereading of the material cited does not suggest that the types X (collection type) and E (enumerator type) need to be disjunct. Thus my Minimum Duck (without Quack):
public class Duck
{
int counter = 0;
public Duck GetEnumerator() { return this; }
public int Current
{
get
{
Console.WriteLine("*Quack*Current*Quack*");
return counter;
}
}
public bool MoveNext()
{
Console.WriteLine("*Quack*MoveNext*Quack*");
return counter++ < 10;
}
}
Edit #2: How is this relevant to AutoCAD?
I've always wondered how the compiler could be so damn sure about the element type of a collection, when encountered in a foreach loop; F# being no different that C#. Many collections in AutoCAD's API are basically broken when accessed in a functional setting; they are missing type information enforced by implementing a generic interface. This compiler quirk explains why they are very efficient when imperative legwork is used, with attendant type safety.