RegexpLike field finder

May 27, 2011 at 12:55 PM
Edited May 27, 2011 at 12:56 PM

Hi. I have such code

 

 

            if (type == 1)
            {
                target.EmergencyContact1AddressAddressLine1 = source.AddressLine1;
                target.EmergencyContact1AddressAddressLine2 = source.AddressLine2;
                target.EmergencyContact1AddressAddressLine3 = source.AddressLine3;
                target.EmergencyContact1AddressTownId = source.AddressTownId;
                target.EmergencyContact1AddressCountryId = source.CountryId;
                target.EmergencyContact1AddressCountyId = source.CountyId;
                target.EmergencyContact1AddressPostcode = source.Postcode;
            }

            if (type == 2)
            {
                target.EmergencyContact2AddressAddressLine1 = source.AddressLine1;
                target.EmergencyContact2AddressAddressLine2 = source.AddressLine2;
                target.EmergencyContact2AddressAddressLine3 = source.AddressLine3;
                target.EmergencyContact2AddressTownId = source.AddressTownId;
                target.EmergencyContact2AddressCountryId = source.CountryId;
                target.EmergencyContact2AddressCountyId = source.CountyId;
                target.EmergencyContact2AddressPostcode = source.Postcode;
            }

So as you can see the target field name consist of {EmergencyContact}{Number}{Tail with matching to the source field name}

Can ValueInjector be used to perform such kind of field finding?

 

EmergencyContact
May 27, 2011 at 2:45 PM

you need an injection that would look like this:

 public class My : ConventionInjection
    {
        protected override bool Match(ConventionInfo c)
        {
            return c.TargetProp.Name.EndsWith(c.SourceProp.Name);
        }
    }