The Caffeinated Penguin

musings of a crackpot hacker

BattleTech

Posted By on April 29, 2005

So, I started work on my BattleTech Mech design app today. Originally, I was going to store all the various tables as XML and then suck them in as a bunch of DataTable objects populating a DataSet. No big deal, right? Well, I got them to load, but since my various widgets are dependant on that data, I needed to do things like get Min and Max values for a certain column. Something like this should have worked (quick and dirty proof of concept test):

Console.WriteLine(Chassis.Tables["chassis"].Select(“Min(weight)”)[0][0].ToString());

Should select the minimum weight from the “chassis” table . The [0][0].ToString gets the first column from the first row and converts it to a string. Now:

Console.WriteLine(Chassis.Tables["chassis"].Select(“weight = 20″)[0][0].ToString());

works just fine. But not the above. It throws an error of:

Unhandled Exception: System.InvalidCastException: Cannot cast from source type to destination type.

I don't know what it's trying to cast that it's getting angry about (the string perhaps?), but I tried to get it to work for about two hours with no luck. It's either a bug in mono or I simply can't do what I want to do.

So, I've implemented it as ArrayLists for now, but the inefficiency of it kind of grates on me, so I might just do a bit of hackishness to compensate for the lack of Min/Max and write a function that iterates through the data set to get the current min and max (this data is NEVER changed by the user inside the application, so I can get away with this approach).

Of course, anyone who has any other brilliant ideas is welcome to suggest away.


Comments

Leave a Reply

Please note: Comment moderation is currently enabled so there will be a delay between when you post your comment and when it shows up. Patience is a virtue; there is no need to re-submit your comment.

Spam protection by WP Captcha-Free