Monday, February 06, 2012
 
   
 
Welcome to my site

First let me say thanks for stopping by my site. My name is David Hanson-Graville and I am a IT consultant working in the UK. Let me make it clear, I am passionate about technology and specifically .net and its various forms. I've programmed in a range of langages, but I can say, I am now at my happiest when coding with c#. I hope my blog is an enjoyable & educational read and please feel free to email me at David.Hanson@OnTheBlog.net if you have any questions. 

Linq to Reflection: Part 1 Minimize
Location: BlogsOnTheBlog    
Posted by: David Hanson Wed, 23 Apr 2008 09:25:08 GMT

Firstly.... before you read this, I would really like feedback on this series of posts and the ideas it outlines. I wanted to get that request made on the first line as apparently most humans skip the next paragraph when searching for info. So with that out of the way I will outline what this post is really about.

 
These posts are the result of a bit of a mishmash of ideas that I have been thinking about of late. The project I am currently working is fully agile, therefore test driven development plays a key role in the day to day work a developer encounters. We perform integration testing, interaction testing, unit testing & business testing as well as a few other kinds of testing during the course of writing functionality. The project has also recently migrated.NET 3.5 and a result we have started to take advantage of some of the languages features such as LINQ.
 
When I first heard of LINQ I must admit I was sceptical. I am one of those developers who likes to have a thorough understanding of the architecture prior to implementing it my code base. (Remember VB web classes anyone).  I picked up the Pro-LINQ book from Apress a while back and spent a weekend reading from cover to cover. So before I continue I will clarify my position on these technologies.
 
LINQ to Objects is superb.
LINQ to XML is just as good.
LINQ to SQL is good but not there yet! (Release 3 Perhaps).
LINQ to Entities (Barge pole and touch come to mind).
 
So with  that said I will try and move onto the focus of these posts. LINQ to Objects has been implemented using .NET 3.5 extension methods. Extension methods allow you to implement instance type methods on existing classes. Even if these classes are sealed or you do not have the source code so you can extend them. So given this new feature it got me thinking about what possible uses there are for extension methods.  LINQ uses them primarily on types of IEnumerable in order to implement query expressions, but I wanted to see if I could use them in a more generic fashion on any type of object.
 
As I felt I had a solution looking for a problem, I decided to bide my time and wait for the problem to present itself. A couple of weeks ago it did!! As said, we are working on a project which has adopted TDD. One of the issue I find with TDD is that I kept feeling I had to break encapsulation principles in order to increase testability. An internal field on a class would need to be set for a specific test condition to pass or an object deep down in my object graph would need to be configured or mocked in order to allow testing. IOC & dependency injection admittedly can help in this area but are not always the simplest of solutions.  So end game is that I want to avoid this wherever possible.
 
Currently, In order to solve some of these problems, our project has a number of utility classes for accessing private members on a reference types. This only goes so far and can be cumbersome to use. What I would ideally like in my tool kit is the ability to seamlessly drill down an object graph using a familiar syntax. More than that, I want to be able to instantly convert those fields or properties to mock objects prior to running my tests.  I want to be able to swap mock frameworks without changing my tests and think more about my test conditions instead of the mocking framework. I want a repeatable pattern.
 
As a result of this I have started work on a library which will provide a simple LINQ 2 Reflection style syntax which will provide facilities for drilling down into any CLR type and performing a number of tasks ranging from (Reading data, Writing data , Mocking , Invocation, monitoring, interception and many other extensible behaviours.).
 
In part 2 I will start to outline some simple uses of these LINQ to reflection extension methods. For the timing being here is a very simple update statement using the extension methods on a person entity.
 
            DateTime DOB = new DateTime(1950, 1, 1);
            //Lets perform an Update on our entity.
            person
                .Field<string>("_firstName").Update("James")
                .Field<string>("_lastName").Update("Brown")
                .Field<DateTime>("_dateOfBirth").Update(DOB);
 
 
 
 
Permalink |  Trackback

Comments (1)   Add Comment
LINQ to Reflection Part 2: Reading Fields    By TrackBack on Fri, 25 Apr 2008 11:34:23 GMT
In part 1 of my LINQ to Reflection series I outlined some of the key drivers behind me creating a set of extension methods that can be used to query any CLR type. I also outlined that I am looking to ...
# The Thinker


Your name:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment   Cancel 
Tweets Minimize
Twitter / LordHanson
  1. LordHanson: #southeastern have once again proved their rolling stock can reach new lows.

    Published Wed, 01 Feb 2012 08:09:05 +0000 by
  2. LordHanson: Checked in at The Cards http://t.co/LANfHukb

    Published Sun, 29 Jan 2012 11:04:51 +0000 by
  3. LordHanson: @BillGates Run for president Bill.

    Published Fri, 27 Jan 2012 08:41:35 +0000 by
  4. LordHanson: @swhelband Again!

    Published Fri, 27 Jan 2012 08:39:44 +0000 by
  5. LordHanson: The update for the Nokia Lumia recently has done wonders for battery life! Good job #Nokia #windowsphone

    Published Fri, 27 Jan 2012 08:36:27 +0000 by
  6. LordHanson: Checked in at Victoria Station http://t.co/L0BJ5smd

    Published Thu, 26 Jan 2012 08:35:41 +0000 by
  7. LordHanson: @pdl_uk VAT No: 924 5933 08 Shoulder again! Dang!

    Published Wed, 25 Jan 2012 21:47:45 +0000 by
  8. LordHanson: @tommyjmquinn I think that would be easier. Next Thursday ok?

    Published Wed, 25 Jan 2012 21:04:46 +0000 by
  9. LordHanson: @tommyjmquinn London bridge doable?

    Published Wed, 25 Jan 2012 20:32:34 +0000 by
  10. LordHanson: @tommyjmquinn so where's the meet?

    Published Wed, 25 Jan 2012 19:04:02 +0000 by
  11. LordHanson: @tommyjmquinn your choice mate. Somewhere easy to get to from Bankside. :-D

    Published Tue, 24 Jan 2012 22:01:20 +0000 by
  12. LordHanson: @tommyjmquinn so Darius, Justin and me confirmed. Thursday good for you? Waiting to hear from Sal.

    Published Tue, 24 Jan 2012 21:47:21 +0000 by
  13. LordHanson: @mark_mann which is illegal I thought!

    Published Tue, 24 Jan 2012 21:46:17 +0000 by
  14. LordHanson: Details on Windows Phone 8 confirms NT kernel http://t.co/5Qg1MILl

    Published Tue, 24 Jan 2012 21:34:11 +0000 by
  15. LordHanson: But next target for framework is #winrt. Need to see if my dependencies like DI, RX, ReactiveUi etc will work. Hmm

    Published Mon, 23 Jan 2012 08:33:16 +0000 by
  16. LordHanson: @pdl_uk hey Phil, how's marathon training going?

    Published Mon, 23 Jan 2012 08:31:37 +0000 by
  17. LordHanson: So I now have a framework for apps which targets .net, Silverlight and windows phone. Thankyou project linker!

    Published Mon, 23 Jan 2012 08:28:08 +0000 by
  18. LordHanson: For some reason dropped twitter for a month. Can't say I missed it really. Maybe I need to broaden my follow list!

    Published Mon, 23 Jan 2012 08:24:44 +0000 by
  19. LordHanson: Soo much hype over SIRI when it came out yet I never see anyone use it and don't know anybody who does either. #apple #sooverhyped

    Published Mon, 23 Jan 2012 08:23:18 +0000 by
  20. LordHanson: #southeastern customer satisfaction survey given to me today. This should be fun! Bit wait......no extremely poor option! Just very poor.

    Published Mon, 23 Jan 2012 08:20:09 +0000 by
Print  
Archive Minimize
Print  
Contact me Minimize
Print  
Microsoft Certs Minimize







Print  
Silverlight News Minimize
Silverlight - Google News
  1. Windows Phone 8 - Silverlight Apps Are Legacy - iProgrammer

    Published Fri, 03 Feb 2012 13:03:27 GMT by
  2. Super Bowl Streaming Fail - StreamingMedia.com

    Published Mon, 06 Feb 2012 05:59:33 GMT by
  3. Delphi Developers Rejoice at Silverlight, FireMonkey and VCL Coming Together ... - San Francisco Chronicle (press release)

    Published Tue, 31 Jan 2012 17:34:58 GMT by
  4. WP7 Upgrades and WP8 - Silverlight or C++ - iProgrammer

    Published Tue, 31 Jan 2012 17:21:58 GMT by
  5. Watch The 2012 Super Bowl Online - SportsGrid

    Published Sun, 05 Feb 2012 23:15:21 GMT by
  6. US viewers can watch Super Bowl on Mac, iOS - Macworld

    Published Sun, 05 Feb 2012 20:22:31 GMT by
  7. Hydra 4 Sharpens Its Teeth, Breathes New Fire - Dr. Dobb's

    Published Sun, 05 Feb 2012 17:25:01 GMT by
  8. Will Silverlight live or die? Microsoft won't say - InfoWorld

    Published Fri, 27 Jan 2012 11:00:46 GMT by
  9. Cablevision Flips Live TV To Laptops With Microsoft Silverlight - Multichannel News

    Published Fri, 27 Jan 2012 17:24:53 GMT by
  10. Do SharePoint & Silverlight Have a Future Together? - CMSWire

    Published Mon, 16 Jan 2012 17:29:27 GMT by
Print