AutoMapper: How to parse an Int from a String and possible to creating rules based on data type?

后端 未结 3 1416
迷失自我
迷失自我 2020-12-30 01:38

I have two models for my form, a ViewModel going to it, and a ControlModel coming from it. The ControlModel has all the same field names and hierarchy, but all of the field

3条回答
  •  清歌不尽
    2020-12-30 02:17

    You could create properties in your source class that cast fields to the types as they exist in the destination. Then use AutoMapper in a plain vanilla manner.

    public class source
    {
      public int _myfield;
    
      public string MyField
      {
        get
        {
           return _myfield.ToString();
        }
      }
    }
    
    public class destination
    {
      public string MyField { get; set; }
    }
    

提交回复
热议问题