• entries
    359
  • comments
    237
  • views
    188615

Tangent: Enumerable interface, part 3.

Sign in to follow this  

87 views

The battle versus IEnumerable has been won!

The type (and IEnumerator) imports nicely now. It's nicely specialized within List, and is all nice and typesafe. The following example code compiles and runs nicely:


public static void main(){
local List<int> x = new List<int>;

x.Add(1);
x.Add(2);
x.Add(3);

local IEnumerator<int> itr = x.GetEnumerator();

while(itr.MoveNext()){
print itr.Current; // 123
}

}





Oddly enough, none of the problems with it were the sort I expected; and didn't have much to do with the specialization of the generic and non-generic bits. The two major bugs were that I neglected to care about explicitly defined interfaces, and I was being dumb about how I new'd dotNet types.

I would generate the object for the .NET type and then store the value in it based off of the return of the invoke. This caused problems for abstract types/interfaces, since they can't just be new'd as is. As a bonus, that should cut down on the number of allocations during common use.

Next in the queue is almost certainly implementing the for loop now that this stuff is done. Not quite sure how that's going to go, so visit the thread about it, and put in your two cents. Damned laze-abouts...
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now