🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Tangent: Enumerable interface, part 3.

Published January 07, 2009
Advertisement
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...
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement