40
1
using System;
2
using AutoMapper;
3
4
public class Person
5
{
6
public string Name { get; set; }
7
public int Age { get; set; }
8
public string Address { get; set; }
9
public string Email { get; set; }
10
11
}
12
13
public class PersonVM
14
{
15
16
public string Name { get; set; }
17
public int Age { get; set; }
18
}
19
public class Program
20
{
21
public static void Main()
22
{
23
24
var config = new MapperConfiguration(cfg => {
25
cfg.CreateMap<Person, PersonVM>().ForMember(x =>x.Name, opt => opt.Ignore());
26
27
});
28
29
IMapper mapper = config.CreateMapper();
30
31
32
var person = new Person { Name="test", Age=10, Email = "test@test.com", Address="Test Address" };
33
34
var personVM = mapper.Map<PersonVM>(person);
35
36
37
Console.WriteLine("\nperson.Name : {0} \nperson.Age : {1} \nperson.Address : {2} \nperson.Email : {3}", person.Name, person.Age, person.Email, person.Address);
38
Console.WriteLine("\npersonVM.Name : {0} \npersonVM.Age : {1} ", personVM.Name, personVM.Age);
39
}
40
}
Cached Result
00:00 - 0
01:00 - 0
02:00 - 0
03:00 - 0
04:00 - 0
05:00 - 0
06:00 - 0
07:00 - 0
08:00 - 100
09:00 - 98.33333333333333
10:00 - 0
11:00 - 0
12:00 - 0
13:00 - 0
14:00 - 0
15:00 - 0
16:00 - 0
17:00 - 0
18:00 - 0
19:00 - 0
20:00 - 0
21:00 - 0
22:00 - 0
23:00 - 0
01:00 - 0
02:00 - 0
03:00 - 0
04:00 - 0
05:00 - 0
06:00 - 0
07:00 - 0
08:00 - 100
09:00 - 98.33333333333333
10:00 - 0
11:00 - 0
12:00 - 0
13:00 - 0
14:00 - 0
15:00 - 0
16:00 - 0
17:00 - 0
18:00 - 0
19:00 - 0
20:00 - 0
21:00 - 0
22:00 - 0
23:00 - 0