Injecting children to a composite object

May 19, 2011 at 4:14 PM

Given this:

class Foo
{
   Bar bar;
   Baz baz;
}

class Bar
{
   string s;
   int i;
}

class Baz
{
   double d;
   float f;
}

What I want to do is:

Foo f = new Foo();

f.InjectFrom(someBar, someBaz);

And have Foo.bar contain values from someBar and Foo.baz contain values from someBaz

But I'm just not getting it from the documentation and examples. Is that flattening, unflattening, or something else entirely?

Do I need to write my own injector?

Note: I am using public properties with getters & setters, the example code above is simplified for readability. 

 

Thanks in advance for any help.

Coordinator
May 19, 2011 at 6:50 PM

you can do this:

f.bar.InjectFrom(someBar);
f.baz.InjectFrom(sombeBaz); 

May 19, 2011 at 7:53 PM

Great, thanks!

That's what I had but it was bugging me. I kept thinking there was a better way to do it.