Transformations ?

I’ve got to say, I am really loving LINQ.  This stuff is so very cool.  One thingy I think is missing though is a formal way of defining a transformation.

A common scenario is data or xml needs to come into and out of business objects.  In the first versions of .Net the means of doing this was reflection based via serializers, or you could create a hard coded serializer, but it was and is a lot of code, and it was tied to the actual business object structure.  Often the data coming in doesn’t exactly match that type or name or structure.  This is where transformations need to be done.  What I would like to see is a formalised transformation structure/mapping, much like an interface or dynamic interface.


Private Transformation AcemCo_To_WidgetCo
   (Name As String) To (Name As String)
   (Address1 as String & Address2 As String) To (Address As String)
   (DOB As String) To (DateOfBirth AS Date)
End Transformation

So given the above, let’s say I had an object, that had the features of the AcmeCo object, Name, Address1, Address 2 and DOB, I could then

Apply Transformation AcemCo_To_WidgetCo On myAcmeObject To myWidgetObject


myWidgetObject = Apply Transformation AcemCo_To_WidgetCo On myAcmeObject As New WidgetObject

In the first case, I would be applying the transformation to the myAcemObject and then transferring the values to an existing myWidgetObject.  In the second sample, I would be creating a new WidgetObject from the transformation.

Note on the transformation declaration I did not define the incoming type and outgoing type though.  That means this transformation would be completely dynamic, and could be applied to any types that meet the field or property requirements of the transformation specification ,such as Name, Address etc.

But we could also make this strongly typed, by specifying the types on the transformation:

Private Transformation AcemCo_To_WidgetCo As AcmeType to WidgetType
   (Name As String) To (Name As String)
   (Address1 as String & Address2 As String) To (Address As String)
   (DOB As String) To (DateOfBirth AS Date)
End Transformation

This code could then be fully verified at compile time, and would be straight property gets/sets.. No reflection required.

I think I would like to see Transformations in VB, and maybe other languages too smile

This entry was posted in 491. Bookmark the permalink.

One Response to Transformations ?

  1. secretGeek says:

    Have you seen this: Snippy – Visual Studio Code Snippet Editor

    You’re gonna have to crush them like a bug Bill!



Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>