Generic Huh What

I actually didn’t expect this to compile, but what I did expect didn’t compile. Since I was in the mood to attempt compilation instead of looking it up on MSDN..

   1:  public static T2 Find<T2, T>(DataConnection connection, List<IWhereCriteria> criteria)
   2:              where T2 : EntityCollectionBase<T>, new()
   3:              where T : EntityBase, new()
   4:          {
   5:              var collection = new T2();
   6:              collection.Initialize(criteria);
   7:   
   8:              return collection;
   9:          }

I’m not sure this is really kosher with the cool kids party, so feel free to rip me on it. I’d rather learn now than pay for a mistake later.

At least this test now passes as a result:

   1:          [Test]
   2:          public void can_fetch_collection_with_query()
   3:          {
   4:              var criteria = new List<IWhereCriteria>();
   5:              criteria.Add(new EqualToValueClause("applicationID", "CON001"));
   6:   
   7:              var results = TradingAccountCollection.Find<TradingAccountCollection, TradingAccount>(Connection, criteria);
   8:   
   9:              Expect(results, Is.Not.Null);
  10:              Expect(results.Count, Is.EqualTo(1));
  11:          }

-j

 
May 26, 2009 22:09 by josh
E-mail | Permalink
blog comments powered by Disqus


about josh

another programmer blogging about his misadventures in writing code.

Contact

contact us for website & software consulting

Decide

decide on pragmatic solutions

Develop

develop your product together

Succeed

achieve your goals with our services