Transformations ?

Posted Fri, Sep 23 2005 16:06 by bill


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.


E.g

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

(1)
Apply Transformation AcemCo_To_WidgetCo On myAcmeObject To myWidgetObject

Or

(2)
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

Filed under:

Comments

# re: Transformations ?

Wednesday, October 05, 2005 8:54 AM by bill

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

http://www.gotdotnet.com/codegallery/codegallery.aspx?id=b0813ae7-466a-43c2-b2ad-f87e4ee6bc39


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

cheers
lb