映射相同对象时valueInjecter中的System.ArgumentException

时间:2014-07-18 11:13:50

标签: c# valueinjecter

我有一个班级:

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; }
    }

我有2个实例。

Object1和Object2

我想注入object2 - > object1用于特定属性。

所以我已经覆盖了匹配方法,如下所示:

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

    }

我正在使用这样的注射器:

object1.InjectFrom(Object2的);

我无法弄清楚为什么我会得到例外。

  

{"类型对象' System.String'无法转换为类型   ' System.Int32'"}

如果我不重写匹配方法它可以工作,但我得到的属性,我不想从object1替换

任何想法?

1 个答案:

答案 0 :(得分:3)

你试图把iolitm(字​​符串)放在iodoco(int)中。

试试这样:

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

}
相关问题