The Minimizer

2008-03-13

Debugging hashes in Boo and C#

Filed under: Programming — theminimizer @ 20:21

Debugging hashes in Boo with SharpDeveloper and C# with Visual Studio is not easy. The keys and values are just not available. So I made a wrapper class for Hash, modelled after ArachnoRuby. Now I can see the sorted keys and values for the first and last hundred elements.

class Person():

name as string
age as int

def constructor(name as string,age as int):
self.name=name
self.age=age

def ToString() as string:
return name+”, “+age.ToString()

class MyHash():

private h as Hash
private sort as bool

Hash as (string):
get : return dump()

def constructor():
h = Hash()

def constructor(sort as bool):
h = Hash()
self.sort=sort

def Add(key, value):
h.Add(key,value)

def dump() as (string):
list = []
for key in h.Keys:
list.Add(key)
list.Sort() if sort
n = h.Count
if n less than 100:
hash = array(string,h.Count)
i=0
for key in list:
hash[i]=key + ” : ” + h[key]
i++
return hash
else:
hash = array(string,100)
for i in range(50):
hash[i]=list[i] + ” : ” + h[list[i]]
for i in range(50):
hash[50+i] = list[n-50+i] + ” : ” + h[list[n-50+i]]
hash[50] = ” ….. …..” if n>100
return hash

class S003():

def Run():
h = MyHash()
for i in range(1000,1050):
h.Add(“adam_” + i.ToString(), i)

No Comments Yet »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.