<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3010726138776241163</id><updated>2012-02-16T01:00:13.497-08:00</updated><category term='.Net 2.0 DataTable Sort'/><category term='Reflection asp.net2.0 List(of T) VB.Net GridView Sorting'/><category term='validation type c# range'/><title type='text'>Code.Trip(this)</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://codetrip.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3010726138776241163/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://codetrip.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Ranjit Thayyil</name><uri>http://www.blogger.com/profile/17167592540741315892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>7</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3010726138776241163.post-3350750595124194006</id><published>2010-01-27T13:42:00.001-08:00</published><updated>2010-01-27T13:49:01.101-08:00</updated><title type='text'>Web Content Management Systems</title><content type='html'>So I've been searching for a good content management system to reccomend to my company and I came across &lt;a href="http://www.dotnetnuke.com/"&gt;Dot Net Nuke&lt;/a&gt; at http://www.dotnetnuke.com/ ! They apparently use the .net framework and from my previous experience with Asp.Net and Asp.Net MVC, I can vouch for their robustness and stability.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3010726138776241163-3350750595124194006?l=codetrip.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codetrip.blogspot.com/feeds/3350750595124194006/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3010726138776241163&amp;postID=3350750595124194006' title='40 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3010726138776241163/posts/default/3350750595124194006'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3010726138776241163/posts/default/3350750595124194006'/><link rel='alternate' type='text/html' href='http://codetrip.blogspot.com/2010/01/web-content-management-systems.html' title='Web Content Management Systems'/><author><name>Ranjit Thayyil</name><uri>http://www.blogger.com/profile/17167592540741315892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>40</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3010726138776241163.post-7678850633576572911</id><published>2008-12-21T18:02:00.001-08:00</published><updated>2008-12-21T18:08:50.689-08:00</updated><title type='text'>Predicates, Action, lambdas and extension</title><content type='html'>&lt;pre&gt;&lt;code&gt;&lt;br /&gt; public class Product&lt;br /&gt;    {&lt;br /&gt;        public string Category{get;set;}&lt;br /&gt;        public string Name { get; set; }&lt;br /&gt;        public decimal Price { get; set; }&lt;br /&gt;    }&lt;br /&gt;    public class Products:IEnumerable&lt;Product&gt;&lt;br /&gt;    {&lt;br /&gt;        public List&lt;Product&gt; _products;&lt;br /&gt;        &lt;br /&gt;        public Products()&lt;br /&gt;        {&lt;br /&gt;            &lt;br /&gt;            _products = new List&lt;Product&gt;();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        public void Add(Product p)&lt;br /&gt;        {&lt;br /&gt;            _products.Add(p);   &lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        public decimal TotalPrice(Predicate&lt;Product&gt; match)&lt;br /&gt;        {&lt;br /&gt;            if (match==null) &lt;br /&gt;                throw new ArgumentNullException();&lt;br /&gt;            &lt;br /&gt;            decimal totalPrice = 0;&lt;br /&gt;            int itemCount = _products.Count;&lt;br /&gt;            for (int i = 0; i &lt; itemCount; i++)&lt;br /&gt;            {&lt;br /&gt;                if (match(_products[i]) == true)&lt;br /&gt;                    totalPrice += _products[i].Price;&lt;br /&gt;&lt;br /&gt;            }&lt;br /&gt;            return totalPrice;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;        public void ForEach(Action&lt;Product&gt; action)&lt;br /&gt;        {&lt;br /&gt;&lt;br /&gt;            for (int i = 0; i &lt; _products.Count; i++)&lt;br /&gt;            {&lt;br /&gt;                action(_products[i]);&lt;br /&gt;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;        #region IEnumerable&lt;Product&gt; Members&lt;br /&gt;&lt;br /&gt;        public IEnumerator&lt;Product&gt; GetEnumerator()&lt;br /&gt;        {&lt;br /&gt;            this._products.GetEnumerator();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        #endregion&lt;br /&gt;&lt;br /&gt;        #region IEnumerable Members&lt;br /&gt;&lt;br /&gt;        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()&lt;br /&gt;        {&lt;br /&gt;            this.GetEnumerator();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        #endregion&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;extensions:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;public static class MyExtensions&lt;br /&gt;    {&lt;br /&gt;        public static int MyCount&lt;T&gt;(this IEnumerable&lt;T&gt; list)   &lt;br /&gt;        {&lt;br /&gt;            return list.Count()/2;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;tests:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;[TestFixture]&lt;br /&gt;    public class PredicateLamdaActionTests&lt;br /&gt;    {&lt;br /&gt;        [Test]&lt;br /&gt;        public void TestNUnit()&lt;br /&gt;        {&lt;br /&gt;            //Assert.Fail();&lt;br /&gt;&lt;br /&gt;           Assert.That(true);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        [Test]&lt;br /&gt;        public void FindPriceTest()&lt;br /&gt;        {&lt;br /&gt;            Products products = new Products();&lt;br /&gt;            products.Add(new Product() { Name = "Pear", Category = "fruit", Price = 2 });&lt;br /&gt;            products.Add(new Product() { Name = "Apple", Category = "fruit", Price = 3 });&lt;br /&gt;            products.Add(new Product() { Name = "Banana", Category = "berry", Price = 2 });&lt;br /&gt;            products.Add(new Product() { Name = "Blueberry", Category = "berry", Price = 2 });&lt;br /&gt;            products.Add(new Product() { Name = "Beans", Category = "vegetable", Price = 2 });&lt;br /&gt;&lt;br /&gt;            Assert.AreEqual(5,products.TotalPrice(p =&gt; p.Category == "fruit"));&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        [Test]&lt;br /&gt;        public void DoWorkOnAllTest()&lt;br /&gt;        {&lt;br /&gt;            Products products = new Products();&lt;br /&gt;            products.Add(new Product() { Name = "Pear", Category = "fruit", Price = 2 });&lt;br /&gt;            products.Add(new Product() { Name = "Apple", Category = "fruit", Price = 3 });&lt;br /&gt;            products.Add(new Product() { Name = "Banana", Category = "berry", Price = 2 });&lt;br /&gt;            products.Add(new Product() { Name = "Blueberry", Category = "berry", Price = 2 });&lt;br /&gt;            products.Add(new Product() { Name = "Beans", Category = "vegetable", Price = 2 });&lt;br /&gt;            //products.ForEach( delegate(Product p){p.Category="fruit";});&lt;br /&gt;              products.ForEach(p=&gt;p.Category="fruit");                  &lt;br /&gt;           &lt;br /&gt;            Assert.AreEqual(11, products.TotalPrice(p =&gt; p.Category == "fruit"));&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;        [Test]&lt;br /&gt;        public void MyCountTest()&lt;br /&gt;        {&lt;br /&gt;            Products products = new Products();&lt;br /&gt;            products.Add(new Product() { Name = "Pear", Category = "fruit", Price = 2 });&lt;br /&gt;            products.Add(new Product() { Name = "Apple", Category = "fruit", Price = 3 });&lt;br /&gt;            products.Add(new Product() { Name = "Banana", Category = "berry", Price = 2 });&lt;br /&gt;            products.Add(new Product() { Name = "Blueberry", Category = "berry", Price = 2 });&lt;br /&gt;            products.Add(new Product() { Name = "Beans", Category = "vegetable", Price = 2 });&lt;br /&gt;            Assert.AreEqual(2, products._products.MyCount());&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3010726138776241163-7678850633576572911?l=codetrip.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codetrip.blogspot.com/feeds/7678850633576572911/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3010726138776241163&amp;postID=7678850633576572911' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3010726138776241163/posts/default/7678850633576572911'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3010726138776241163/posts/default/7678850633576572911'/><link rel='alternate' type='text/html' href='http://codetrip.blogspot.com/2008/12/predicates-action-lambdas-and-extension.html' title='Predicates, Action, lambdas and extension'/><author><name>Ranjit Thayyil</name><uri>http://www.blogger.com/profile/17167592540741315892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3010726138776241163.post-298470576557773073</id><published>2008-12-07T11:41:00.001-08:00</published><updated>2008-12-21T17:27:11.546-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='validation type c# range'/><title type='text'>A Rangeable, Validated Type</title><content type='html'>As of now in .Net, we have support for Nullable types. What I really wish for is a type that would support ranges or regexes.  This would enforce method calls boundaries to be well defined well defined from service oriented point of view.&lt;br /&gt;&lt;br /&gt;Having such an ability will let us remove validation code from the method body and move it to the parameter/argument level, therefore, fixing  responsibility of sending validated variables to the calling method.&lt;br /&gt;&lt;br /&gt;If the calling method passes a variable that does not support the validation rule, an invalid argument exception is thrown!&lt;br /&gt;&lt;br /&gt;I propose a type called ValidVariable or ValidateableVar&lt;br /&gt;&lt;br /&gt;examples:&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;//ensure that only 2 digit numbers are added&lt;br /&gt;&lt;br /&gt;public int Add2DigitNumbers(ValidVariable&lt;int&gt;(10,99) first,ValidVariable&lt;int&gt;(10,99) second)&lt;br /&gt;{&lt;br /&gt;...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;//ensure only valid emails are supported&lt;br /&gt;&lt;br /&gt;public  void SetEmail(ValidVariable&lt;string&gt;(regex_for_email))&lt;br /&gt;{&lt;br /&gt;...&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;If only the next version of c# supported it! or maybe I will start a project on CodePlex.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3010726138776241163-298470576557773073?l=codetrip.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codetrip.blogspot.com/feeds/298470576557773073/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3010726138776241163&amp;postID=298470576557773073' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3010726138776241163/posts/default/298470576557773073'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3010726138776241163/posts/default/298470576557773073'/><link rel='alternate' type='text/html' href='http://codetrip.blogspot.com/2008/12/rangeable-validated-type.html' title='A Rangeable, Validated Type'/><author><name>Ranjit Thayyil</name><uri>http://www.blogger.com/profile/17167592540741315892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3010726138776241163.post-481421568154092383</id><published>2008-01-12T13:55:00.000-08:00</published><updated>2008-12-21T17:38:37.991-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='.Net 2.0 DataTable Sort'/><title type='text'>Easiest way to sort a datatable</title><content type='html'>If it is not typed:&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;Dim  table1,table2 as DataTable&lt;br /&gt;table1 = GetDataTable()&lt;br /&gt;table1.DefaultView.Sort = "ColumnName"&lt;br /&gt;table2 = table1.DefaultView.ToTable()&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;If the DataTable is typed:&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;Dim  table1 as MyDataTable 'MyDataTable is a strongly typed DataTable&lt;br /&gt;Dim table2 as New MyDataTable()&lt;br /&gt;table1 = GetDataTable()&lt;br /&gt;table1.DefaultView.Sort = "ColumnName"&lt;br /&gt;table2.Load(table1.DefaultView.ToTable().CreateDataReader)&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;As simple as that.&lt;br /&gt;&lt;br /&gt;This may not be very efficient but is very easy :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3010726138776241163-481421568154092383?l=codetrip.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codetrip.blogspot.com/feeds/481421568154092383/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3010726138776241163&amp;postID=481421568154092383' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3010726138776241163/posts/default/481421568154092383'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3010726138776241163/posts/default/481421568154092383'/><link rel='alternate' type='text/html' href='http://codetrip.blogspot.com/2008/01/easiest-way-to-sort-datatable.html' title='Easiest way to sort a datatable'/><author><name>Ranjit Thayyil</name><uri>http://www.blogger.com/profile/17167592540741315892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3010726138776241163.post-7239378505400359728</id><published>2007-03-01T18:05:00.000-08:00</published><updated>2008-12-21T17:29:44.404-08:00</updated><title type='text'>Why IEquatable ?</title><content type='html'>In the .net framework 2.0, a new interface IEquatable&amp;lt;T&amp;gt; has been introduced.  Implementing it in your classes would give you a type safe way of equating your class instances. &lt;br /&gt;&lt;br /&gt;The default .equals of the System.Object does a reference check and is not particularly useful when you want to equate instances of your class based on say certain fields. The workaround in .net 1.1 was to override the .equals(object o) , but this meant that additional type checking had to be done. Now with Generics, &lt;br /&gt;IEquatable&amp;lt;T&amp;gt; gives you a type safe method to implement your class instance equality check.&lt;br /&gt;&lt;br /&gt;I wrote some simple code to figure it all out:&lt;br /&gt;&lt;br /&gt;First, A class which doesn't implement IEquatable ....&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;using System;&lt;br /&gt;&lt;br /&gt;namespace test&lt;br /&gt;{&lt;br /&gt;    class RegularAnimal :Animal&lt;br /&gt;    {&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;        public RegularAnimal(int legs, string sound, string species)&lt;br /&gt;        {&lt;br /&gt;            this.legs = legs;&lt;br /&gt;            this.sound = sound;&lt;br /&gt;            this.species = species;&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        public void Introduce()&lt;br /&gt;        {&lt;br /&gt;            Console.WriteLine("I am a regular " + species + "  I have " + legs.ToString() + " legs and I " + sound);&lt;br /&gt;        }&lt;br /&gt;       &lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/code&gt; &lt;br /&gt;&lt;br /&gt;Now the same class that implements IEquatable&amp;lt;T&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;using System;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;namespace test&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;    class EquatableAnimal : Animal, IEquatable&amp;lt;EquatableAnimal&amp;gt;&lt;br /&gt;    {&lt;br /&gt;&lt;br /&gt;        public EquatableAnimal(int legs, string sound, string species)&lt;br /&gt;        {&lt;br /&gt;            this.legs = legs;&lt;br /&gt;            this.sound = sound;&lt;br /&gt;            this.species = species;&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        public void Introduce()&lt;br /&gt;        {&lt;br /&gt;            Console.WriteLine("I am an equatable " + species + "  I have " + legs.ToString() + " legs and I " + sound);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;        public bool Equals(EquatableAnimal other)&lt;br /&gt;        {&lt;br /&gt;            return (this != null &amp;&amp; this.sound == other.sound);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;Now some code to put the classes to test:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;static void Main(string[] args)&lt;br /&gt;        {&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;            RegularAnimal regular_cat = new RegularAnimal(4, "meow", "cat");&lt;br /&gt;            RegularAnimal regular_dog = new RegularAnimal(4, "bark", "dog");&lt;br /&gt;            RegularAnimal regular_siameseCat = new RegularAnimal(4, "meow", "siamese cat");&lt;br /&gt;&lt;br /&gt;            regular_cat.Introduce();&lt;br /&gt;            regular_dog.Introduce();&lt;br /&gt;            regular_siameseCat.Introduce();&lt;br /&gt;            IsEqual(regular_cat, regular_dog);&lt;br /&gt;            IsEqual(regular_cat, regular_siameseCat);&lt;br /&gt;&lt;br /&gt;            EquatableAnimal cat = new EquatableAnimal(4, "meow", "cat");&lt;br /&gt;            EquatableAnimal dog = new EquatableAnimal(4, "bark", "dog");&lt;br /&gt;            EquatableAnimal siameseCat = new EquatableAnimal(4, "meow", "siamese cat");&lt;br /&gt;            cat.Introduce();&lt;br /&gt;            dog.Introduce();&lt;br /&gt;            siameseCat.Introduce();&lt;br /&gt;            IsEqual(cat, dog);&lt;br /&gt;            IsEqual(cat, siameseCat);&lt;br /&gt;&lt;br /&gt;            &lt;br /&gt;                  &lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        public static void IsEqual(EquatableAnimal animal1, EquatableAnimal animal2)&lt;br /&gt;        {&lt;br /&gt;            if (animal1.Equals(animal2))&lt;br /&gt;            {&lt;br /&gt;                Console.WriteLine("We are the same: " + animal1.species + " and " + animal2.species);&lt;br /&gt;            }&lt;br /&gt;            else&lt;br /&gt;            {&lt;br /&gt;                Console.WriteLine("We are not the same: " + animal1.species + " and " + animal2.species);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        public static void IsEqual(RegularAnimal animal1, RegularAnimal animal2)&lt;br /&gt;        {&lt;br /&gt;            if (animal1.Equals(animal2))&lt;br /&gt;            {&lt;br /&gt;                Console.WriteLine("We are the same: " + animal1.species + " and " + animal2.species);&lt;br /&gt;            }&lt;br /&gt;            else&lt;br /&gt;            {&lt;br /&gt;                Console.WriteLine("We are not the same: " + animal1.species + " and " + animal2.species);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;      &lt;br /&gt;&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The results(click on the picture to enlarge):&lt;br /&gt;&lt;a href="http://bp3.blogger.com/_fLaAO4wg0uc/ReeMnus0-KI/AAAAAAAAAj4/aCa_8-vGfl0/s1600-h/op.GIF"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;" src="http://bp3.blogger.com/_fLaAO4wg0uc/ReeMnus0-KI/AAAAAAAAAj4/aCa_8-vGfl0/s400/op.GIF" border="0" alt=""id="BLOGGER_PHOTO_ID_5037149322416027810" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;B&gt;&lt;br /&gt;I am a regular cat  I have 4 legs and I meow&lt;br /&gt;I am a regular dog  I have 4 legs and I bark&lt;br /&gt;I am a regular siamese cat  I have 4 legs and I meow&lt;br /&gt;We are not the same: cat and dog&lt;br /&gt;We are not the same: cat and siamese cat&lt;br /&gt;I am an equatable cat  I have 4 legs and I meow&lt;br /&gt;I am an equatable dog  I have 4 legs and I bark&lt;br /&gt;I am an equatable siamese cat  I have 4 legs and I meow&lt;br /&gt;We are not the same: cat and dog&lt;br /&gt;We are the same: cat and siamese cat&lt;br /&gt;Press any key to continue . . .&lt;br /&gt;&lt;/B&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The 'EquatableAnimal' compares the 'sound' field to identify animals of the same species while the RegularAnimal equality check fails since we are not overriding the Object.equals(Object o).If we had gone that route instead of implementing the IEquatable interface, we'd need to introduce this code in the RegularAnimal class:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt; public override bool Equals(object obj)&lt;br /&gt;        {&lt;br /&gt;            return ((obj != null) &amp;&amp; (obj.GetType() == this.GetType()) &amp;&amp; ((RegularAnimal)obj).sound == this.sound);&lt;br /&gt;                &lt;br /&gt;                                &lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Useful links:&lt;br /&gt;&lt;a href="http://www.microsoft.com/mspress/books/sampchap/5353.aspx"&gt;http://www.microsoft.com/mspress/books/sampchap/5353.aspx&lt;/a&gt;&lt;br /&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms131187.aspx"&gt;http://msdn2.microsoft.com/en-us/library/ms131187.aspx&lt;/a&gt;&lt;br /&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms379564(vs.80).aspx"&gt;http://msdn2.microsoft.com/en-us/library/ms379564(vs.80).aspx&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3010726138776241163-7239378505400359728?l=codetrip.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codetrip.blogspot.com/feeds/7239378505400359728/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3010726138776241163&amp;postID=7239378505400359728' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3010726138776241163/posts/default/7239378505400359728'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3010726138776241163/posts/default/7239378505400359728'/><link rel='alternate' type='text/html' href='http://codetrip.blogspot.com/2007/03/why-iequatable.html' title='Why IEquatable ?'/><author><name>Ranjit Thayyil</name><uri>http://www.blogger.com/profile/17167592540741315892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp3.blogger.com/_fLaAO4wg0uc/ReeMnus0-KI/AAAAAAAAAj4/aCa_8-vGfl0/s72-c/op.GIF' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3010726138776241163.post-2045023762740981532</id><published>2007-02-01T13:55:00.000-08:00</published><updated>2008-12-21T17:36:53.852-08:00</updated><title type='text'>Enum and DropDowns</title><content type='html'>So I need to get the name and value of an Enum to tie sensibly to a DropDownList. This is how you do it:&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;Enum definition:&lt;br /&gt;&lt;br /&gt;    public enum Categories&lt;br /&gt;    {&lt;br /&gt;        Wildlife,&lt;br /&gt;        Resorts,&lt;br /&gt;        Beer,&lt;br /&gt;        Other&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;To tie to DropDownList called ddCategory: &lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;    ddCategory.DataSource = Enum.GetNames(typeof(Categories));&lt;br /&gt;    ddCategory.DataBind();&lt;br /&gt;&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;To set the selected value:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;    ddCategory.SelectedValue = Enum.GetName(typeof(grr.Categories),1) // or just "Wildlife"&lt;br /&gt;&lt;/pre&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3010726138776241163-2045023762740981532?l=codetrip.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codetrip.blogspot.com/feeds/2045023762740981532/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3010726138776241163&amp;postID=2045023762740981532' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3010726138776241163/posts/default/2045023762740981532'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3010726138776241163/posts/default/2045023762740981532'/><link rel='alternate' type='text/html' href='http://codetrip.blogspot.com/2007/02/enum-and-dropdowns.html' title='Enum and DropDowns'/><author><name>Ranjit Thayyil</name><uri>http://www.blogger.com/profile/17167592540741315892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3010726138776241163.post-4422559211954197384</id><published>2007-01-30T13:39:00.000-08:00</published><updated>2008-12-21T17:35:49.636-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Reflection asp.net2.0 List(of T) VB.Net GridView Sorting'/><title type='text'>Object to DataTable</title><content type='html'>When I lay my hands on ASP.NET 2.0, I was thrilled to use Generics in the form of List( of T) and used it to create collections of my business objects. I was even more excited to use the ObjectDataSource control and bind it to a GridView. But when I tried sorting the GridView, I got a runtime error which said that sorting of List (of T) is not supported and suggested using a DataTable or DataSet! Googling for a few minutes, I learned that to enable sorting for my collection class (in this case a Generic List), I need to first create a custom collection and then implement the IComparable interface. And then, I had to setThe ObjectDataSource's SortExpression.&lt;br /&gt;&lt;br /&gt;&lt;p&gt;I was too lazy to do all this and also didn't want my code scattered in multiple events so I decided to write a bit of 'reflective' code to convert my List(of T) to a DataTable. All I had to do then is Databind the DataTable and let GridView handle sorting.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;The class cList2Table has a method to convert your System.Generics.List(of T) to a DataTable. cList2Table takes a generic list as its constructor parameter and returns a DataTable when you call the GetTable() method. &lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;Imports System.Reflection&lt;br /&gt;Public Class cObjectToTable(Of T)    &lt;br /&gt;Dim objectCollection As List(Of T)    &lt;br /&gt;Public Sub New(ByVal objectCollection As List(Of T))&lt;br /&gt;        Me.objectCollection = objectCollection&lt;br /&gt;   End Sub&lt;br /&gt;   Public Function GetTable() As DataTable&lt;br /&gt;        Dim table As New DataTable&lt;br /&gt;        Dim objectType As Type = GetType(T)&lt;br /&gt;        Dim objectProperties As PropertyInfo() = objectType.GetProperties&lt;br /&gt;      'create a column for each property in the class&lt;br /&gt;        For Each propertyItem As PropertyInfo In objectProperties            table.Columns.Add(New DataColumn(propertyItem.Name, propertyItem.PropertyType))&lt;br /&gt;        Next&lt;br /&gt;    For Each item As T In objectCollection&lt;br /&gt;    'create a new row based on the table structure we just created  Dim row As DataRow = table.NewRow()&lt;br /&gt;         'copy object data to the datarow&lt;br /&gt;       For Each propertyItem As PropertyInfo In objectProperties&lt;br /&gt;                row(propertyItem.Name) = propertyItem.GetValue(item, Nothing)&lt;br /&gt;            Next&lt;br /&gt;        'add row to the table&lt;br /&gt;            table.Rows.Add(row)&lt;br /&gt;        Next&lt;br /&gt;    Return table&lt;br /&gt;End Function&lt;br /&gt;End Class&lt;br /&gt;&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;Now I usually like to see schema in the GridView during design time,So I filled my typed DataSet with the following snippet of code.&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;Dim loTable As New dsSection.dtSectionDataTable&lt;br /&gt;loTable.Load(loObject2Table.GetTable().CreateDataReader)&lt;/pre&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3010726138776241163-4422559211954197384?l=codetrip.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codetrip.blogspot.com/feeds/4422559211954197384/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3010726138776241163&amp;postID=4422559211954197384' title='9 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3010726138776241163/posts/default/4422559211954197384'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3010726138776241163/posts/default/4422559211954197384'/><link rel='alternate' type='text/html' href='http://codetrip.blogspot.com/2007/01/object-to-table.html' title='Object to DataTable'/><author><name>Ranjit Thayyil</name><uri>http://www.blogger.com/profile/17167592540741315892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>9</thr:total></entry></feed>
