Object Binding Utility

I like the clean separation of public and domain objects (so nHibernate won't help here) from each other, which makes me write a lot of code to map one object to another. What tools / plugins are there to do the tedious manual execution of this mapping in .NET? M Whenever I do this on Google, he thinks that I want to do ORM, which I am not looking for. Thanks!

EDIT 19: 33CST: Well, I wrote a very simple application (very quickly written code) demonstrating what I'm looking for. I'm just wondering if there is a VS plugin that will do this for me.

VS2008 Solution

+5
source share
4 answers

So, a seemingly unsatisfied solution at runtime, I wrote a small utility that will create mappings in the code. You can download the source below and write better error handling, etc. Etc. I would appreciate any interesting changes you made, it was done in a hurry, but it works. Please keep in mind that the code is released under the LGPL .

Object Mapping Utility Source Code

UPDATE JUNE 23, 2009 . I made some updates to the code that cleaned it up (a little), and also added the ability to save the mapping to a file so that it can be modified later.

+6
source

, AutoMapper. , .

+14

Otis. *.otis.xml, :

<?xml version="1.0" encoding="utf-8" ?> 
<otis-mapping xmlns="urn:otis-mapping-1.0">
<class name="Otis.Tests.UserDTO, Otis.Tests" source="Otis.Tests.Entity.User, Otis.Tests" >
    <member name="Id" />
    <member name="Age" />
    <member name="UserName" expression="$UserName.ToUpper()" nullValue="[unknown]" />
    <member name="FullName" expression="[$FirstName + ' ' + $LastName]" />
    <member name="ProjectCount" expression="$Projects.Count" />
    <member name="Title" expression="$Gender" >
        <map from="Gender.Male" to="Mr." />     <!-- projections -->
        <map from="Gender.Female" to="Mrs." />
    </member> 
    <member name="Birthday"  expression="$BirthDate" format="Born on {0:D}"/>
    <member name="ProjectCount" expression="$Projects.Count" />
    <member name="AvgTaskDuration" expression="avg:$Projects/Tasks/Duration" />
    <member name="MaxTaskDuration" expression="max:$Projects/Tasks/Duration" />             
</class>

:

// configure the new Configuration object using metadata of types in the current assembly
Configuration cfg = new Configuration();            // instantiate a new Configuration, one per application is needed
cfg.AddAssembly(Assembly.GetExecutingAssembly());   // initialize it

, ?;)

+3

ValueInjecter, , ,

  • object ↔ object
  • object ↔ Form/WebForm
  • DataReader →

, :

+3

All Articles