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

rod.Commons - Goes public

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

Every developer has his own utility library where collects very useful classes. I decided to share my pack of tricky tools which are named "rod.Commons". I’m currently doing some refactoring and code cleaning to make it more readable so you will find not much code there yet. rod.Commons is available in Google Code - http://code.google.com/p/rodcommons/. I hope that some of you will find it useful and I will be appreciated for any comments and ideas.

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