0

I have a class:

public class LotInfo
    {
        public string lotn { get; set; }
        public string imlitm { get; set; }
        public string imdsc { get; set; }
        public string wplotn { get; set; }
        public int wptrdj { get; set; }
        public DateTime wptrdj_d { get; set; }
        public string wplitm { get; set; }
        public int wptrqt { get; set; }
        public string wpkyfn { get; set; }
        public int wpdoco { get; set; }
        public string iolitm { get; set; }
        public string iodcto { get; set; }
        public int iodoco { get; set; }
        public int ioub04 { get; set; }
    }

I have 2 instances.

Object1 and Object2

I want to inject object2 -> object1 for specific properties.

So i have overridden the Match method like this:

public class LotInfoInject : ConventionInjection
    {
        protected override bool Match(ConventionInfo c)
        {
            return c.SourceProp.Name.StartsWith("io");
        }

    }

and i am using the injecter like this:

object1.InjectFrom(object2);

I cant figure out why i am getting the exception.

{"Object of type 'System.String' cannot be converted to type 'System.Int32'."}

If i DONT override the Match method it works but i am getting properties that i dont want replaced from object1

any ideas?

e4rthdog
  • 5,103
  • 4
  • 40
  • 89
  • 1
    besides specifying that the source should start with io you should also specify that target property should equal the source property – Omu Jul 18 '14 at 11:30
  • you can also override SetValue in case you want to go from string to int – Omu Jul 18 '14 at 11:33

1 Answers1

3

You're trying to put iolitm (string) in iodoco (int).

Try like this:

public class LotInfoInject : ConventionInjection
{
    protected override bool Match(ConventionInfo c)
    {
        return c.SourceProp.Name.StartsWith("io")
            && c.SourceProp.Name == c.TargetProp.Name;
    }

}
Jan Van Herck
  • 2,254
  • 17
  • 15