let's say you have this 2 classes:
        public class Foo
        {
            public Foo Foo1 { get; set; }
            public Foo Foo2 { get; set; }
            public string Name { get; set; }
            public int Age { get; set; }
        }

        public class FlatFoo
        {
            public string Foo1Foo2Foo1Name { get; set; }
            public string Foo1Name { get; set; }
            public string Foo2Name { get; set; }
            public string Foo1Age { get; set; }
        }

you can map them like this:

         var flat = new FlatFoo
                           {
                               Foo1Foo2Foo1Name = "cool",
                               Foo1Name = "abc",
                               Foo2Name = "123",
                           };

            var unflat = new Foo();

            unflat.InjectFrom<UnflatLoopValueInjection>(flat);

            //unflat.Foo1.Foo2.Foo1.Name = "cool";
            //unflat.Foo1.Name = "abc";
            //unflat.Foo2.Name = "123";

you can also extend the UnflatLoopValueInjection or UnflatLoopValueInjection<TSourceProperty, TTargetProperty> (to unflat from one type to another) , example:
        public class IntToStringUnflat : UnflatLoopValueInjection<int, string>
        {
            protected override string SetValue(int sourceValue)
            {
                return sourceValue.ToString();
            }
        }

Last edited Jun 14, 2010 at 12:10 PM by o, version 1

Comments

No comments yet.