June 22, 2008

ReflectionHelper - DSL-like reflection manipulating

Filed under: .NET, C#, rod.Commons

I’ve added ReflectionHelper and ReflectionHelperExtensions classes in rod.Commons project. These classes are useful for simple object modifying by reflection.

ReflectionHelper is for NET 2.0 and above and can be used like this:

   1: public void ChangeTransferAmountToTenDollars(Transfer transfer)
   2: {
   3:     return ReflectionHelper.For(transfer)
   4:         .Field("amount")
   5:         .SetValue(10)
   6:         .Property("Currency")
   7:         .SetValue("USD")
   8:         .Return<Transfer>();
   9: }

ReflectionHelperExtensions is for NET 3.5+ and it is just extension adding Reflect() method for easier using ReflectionHelper like this:

   1: public void ChangeTransferAmountToTenDollars(Transfer transfer)
   2: {
   3:     return transfer.Reflect()
   4:         .Field("amount")
   5:         .SetValue(10)
   6:         .Property("Currency")
   7:         .SetValue("USD")
   8:         .Return<Transfer>();
   9: }

kick it on DotNetKicks.com

Comments »

The URI to TrackBack this entry is: http://rod.blogsome.com/2008/06/22/reflectionhelper-dsl-like-reflection-manipulating/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>


Get free blog up and running in minutes with Blogsome | Theme designs available here