Alessandro
Alessandro

Reputation: 61

ValueInjecter: how to ignore some properties while performing .InjectFrom<UnflatLoopValueInjection>(data)?

I'm using ValueInjecter instead of AutoMapper. I'm trying to perform unflattening operation using

.InjectFrom<UnflatLoopValueInjection>(model)

It works, but I would also like to specity some properties to ignore during the unflattening operation, for example writing something like:

.InjectFrom<UnflatLoopValueInjection>(new IgnoreProperties("Prop1", "Prop2"), model)

or

.InjectFrom<UnflatLoopValueInjection>(model).IgnoreProperties("Prop1", "Prop2")

Any ideas?

Upvotes: 4

Views: 1890

Answers (2)

Rami A.
Rami A.

Reputation: 10582

With the latest version of Omu.ValueInjecter (v3.1.1 as of this writing), this feature is built-in:

instanceA.InjectFrom(new LoopInjection(new[] { "Prop1", "Prop2" }), instanceB);

Prop1 and Prop2 will be ignored.

This feature may have existed in previous versions, but isn't in v2.3 for example.

Upvotes: 7

Omu
Omu

Reputation: 71198

you can grab the source code for the UnflatLoopValueInjection and create your own injection which has this feature and whatever else you need.

here's the code for it: http://valueinjecter.codeplex.com/SourceControl/latest#ValueInjecter/UnflatLoopValueInjection.cs

you could add a Property Ignored properties or put it in the constructor, and where you have the line

 var prop = sourceProp;

 //add
 if(ignoredProps.Contains(prop) continue;

this should give you a quick idea of what you can do

Upvotes: 0

Related Questions