Thursday, November 20, 2008
 
   
 
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. 

Archive Minimize
Print  
Contact me Minimize
Print  
Microsoft Certs Minimize







Print  
Silverlight News Minimize
silverlight - Google News
  1. Major League Baseball Switches From Silverlight to Flash - PC World

    Published Thu, 20 Nov 2008 16:53:44 GMT by
  2. Review: Silverlight, for real this time - Computerworld

    Published Wed, 19 Nov 2008 21:07:45 GMT by
  3. Where to find good Silverlight applications - InfoWorld

    Published Thu, 20 Nov 2008 15:27:23 GMT by
  4. MLB.com drops Silverlight for Adobe Flash - CNET News

    Published Mon, 17 Nov 2008 22:42:14 GMT by
  5. Adobe Flash Hits Home Run With MLB - InformationWeek

    Published Thu, 20 Nov 2008 10:22:39 GMT by
  6. Silverlight, for real this time - NetworkWorld.com

    Published Tue, 18 Nov 2008 21:11:49 GMT by
  7. .NET similarities prove golden for Silverlight - SDTimes.com

    Published Wed, 19 Nov 2008 20:11:43 GMT by
  8. Novell and Microsoft sanction Silverlight work-alike for Linux - BetaNews

    Published Wed, 19 Nov 2008 20:25:22 GMT by
  9. Silverlight Beta for Linux on the Road to Silverlight 3 on Windows - Softpedia

    Published Wed, 19 Nov 2008 16:19:45 GMT by
  10. Microsoft crashes Adobe RIA party - Register

    Published Mon, 17 Nov 2008 22:19:52 GMT by
Print  
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