Louis Rhys
Louis Rhys

Reputation: 35627

ValueInjecter to ignore cases when mapping properties

For example, I want to map property Foo.ID to Bar.Id, is it possible?

Upvotes: 4

Views: 866

Answers (1)

nemesv
nemesv

Reputation: 139758

You need to create your own ConventionInjection where you compare the property names case insensitivly:

public class IgnoreCaseInjection : ConventionInjection
{
     protected override bool Match(ConventionInfo c)
     {
         return String.Compare(c.SourceProp.Name, c.TargetProp.Name, 
                               StringComparison.OrdinalIgnoreCase) == 0;
     }
}

And you need to use it with

var foo = new Foo() { ID = 1};
var bar = new Bar();
bar.InjectFrom<IgnoreCaseInjection>(foo);

Upvotes: 6

Related Questions