Friday, September 10, 2010
 
   
 
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 3: Updating Fields Minimize
Location: BlogsOnTheBlog    
Posted by: David Hanson Mon, 28 Apr 2008 13:30:07 GMT
In part 2 of this LINQ 2 Reflection series I took you through how we go about querying fields that may existing within an object graph. Before we proceed, it’s important to remember that a call to object.Field<T> will return an instance of type Linq.Reflection.Field. As part 2 focused purely the reading fields it’s about time we take a look at how we can go about updating them. If we look at the intellisense that Visual Studio provides for the Field<T> class we can see that this class has an Update<T> method. Shown below.
 
 
Firstly, as the Update<T> method is contextual, there is no requirement to pass the name of the field we wish to update as this can be inferred from its parent. Secondly, As the Field<T> returns a generic class of type T it also allows us to infer the Type of value we wish to update. Below is a simple update statement on a person entity.
 
person
    .Field<string>("_firstName").Update("James")
    .Field<string>("_lastName").Update("Brown")
    .Field<DateTime>("_dateOfBirth").Update(DOB);
 
The Update<T> method of the Field<T> class returns an instance of the parent object we are currently working with. Internally the Field<T> class passes the parent context down our chained methods. Therefore we have the ability to move up the object graph if so desired. In this situation, where we are updating 1 of many fields on the parent context, its important that the return value from Update<T> is that of the parent object.
 

As that’s pretty much it for updating fields using LINQ to Reflection. You can call the Update<T> on and Field<T> or Property<T> accessor. As this point in our series you have the information you need to drill down any object reading and writing property/field values to suit your tests scenarios.  

In part 4 we will start looking at how we can leverage the power of these extensions methods by showing how we can mock internal objects without breaking the rules of encapsulation.

Permalink |  Trackback

Your name:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment   Cancel 
Tweets Minimize
Twitter / LordHanson
  1. LordHanson: Experienced .net dev in sydney for next 5 months if anyone needs me. CV on request just tweet me.

    Published Sun, 29 Aug 2010 05:41:05 +0000 by
  2. LordHanson: Flash on iPad....nice. http://www.tipb.com/2010/07/04/frash-android-flash-ported-ipad/

    Published Sun, 04 Jul 2010 22:07:55 +0000 by
  3. LordHanson: Anyone noticed that when typing on your iPhone it sounds like your holding a gieger counter?

    Published Sun, 04 Jul 2010 22:05:28 +0000 by
  4. LordHanson: Missing wacko's music... What's happened to the album he was working on before he died?

    Published Fri, 25 Jun 2010 23:01:45 +0000 by
  5. LordHanson: New version of Connectify cannot recognise my active Internet connection! Had to roll back to previous version! #fail

    Published Fri, 25 Jun 2010 22:54:54 +0000 by
  6. LordHanson: vuvuzela blowing spoils the world cup! Fact!

    Published Mon, 14 Jun 2010 05:08:43 +0000 by
  7. LordHanson: About http://www.theaustralian.com.au/business/news/us-competition-regulators-to-investigate-apple/story-e6frg90x-1225878779986

    Published Mon, 14 Jun 2010 00:04:45 +0000 by
  8. LordHanson: In the camper van and a storm is coming.....How exciting.

    Published Sun, 25 Apr 2010 04:39:48 +0000 by
  9. LordHanson: My vaio p is doing well while travelling. 3g Internet, HD movies, digital tv, photo editing, wifi router for iPods and much more. Love it

    Published Wed, 10 Mar 2010 10:29:19 +0000 by
  10. LordHanson: Ok so I need to stay techie while away from a computer for a year. Anyone got any ideas.

    Published Mon, 22 Feb 2010 12:31:09 +0000 by
  11. LordHanson: Sitting in YHA Glebe Sydney waiting for the movie night to start

    Published Thu, 18 Feb 2010 08:13:10 +0000 by
  12. LordHanson: Madness today. We only booked our return tickets to bangkok on the wrong day! Luckily we managed to change them!

    Published Wed, 10 Feb 2010 15:54:37 +0000 by
  13. LordHanson: HTML5 the future? http://bit.ly/6yf9Bu

    Published Tue, 09 Feb 2010 13:43:48 +0000 by
  14. LordHanson: Last night in Bangkok! Good fun!

    Published Thu, 04 Feb 2010 18:09:38 +0000 by
  15. LordHanson: @trampussandal Dad? lol

    Published Thu, 04 Feb 2010 05:26:39 +0000 by
  16. LordHanson: Im sitting in a coffee shop in my home town of epsom thinking... Man the day has finally arrived. I can feel the stress lifting.

    Published Mon, 01 Feb 2010 09:05:13 +0000 by
  17. LordHanson: So what excuse will apple use to not allow flash or silverlight to run on the ipad this time I wonder.

    Published Fri, 29 Jan 2010 19:07:46 +0000 by
  18. LordHanson: Yay just manage to upgrade from vista ultimate to windows 7 enterprise by using the registry hack trick. No reinstalls.

    Published Wed, 27 Jan 2010 07:18:07 +0000 by
  19. LordHanson: @swhelband Sure am...http://bit.ly/aZ6Xvd

    Published Tue, 26 Jan 2010 19:05:18 +0000 by
  20. LordHanson: I finished work today in prep for travelling. I must admit as i left the office i felt a little emotional. Sign of a good job with great ...

    Published Tue, 26 Jan 2010 17:48:49 +0000 by
Print  
Archive Minimize
Print  
Contact me Minimize
Print  
Microsoft Certs Minimize







Print  
Silverlight News Minimize
Silverlight - Google News
Print