-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapper.cs
More file actions
54 lines (43 loc) · 1.88 KB
/
Copy pathMapper.cs
File metadata and controls
54 lines (43 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
namespace MBDEVproAPI.BLL
{
internal class Mapper
{
/// <summary>
///
/// </summary>
/// <typeparam name="DestinationObject"></typeparam>
/// <param name="sourceObject"></param>
/// <param name="destinationObject"></param>
/// <param name="isPropertyTypeNeedsMatch"></param>
/// <returns></returns>
internal static DestinationObject MapObject<DestinationObject>(object sourceObject,
DestinationObject destinationObject,
bool isPropertyTypeNeedsMatch = true) where DestinationObject : class
{
//Boundary Condition
if (sourceObject == null || destinationObject == null)
{
return destinationObject;
}
PropertyInfo[] destinationPropList = destinationObject.GetType().GetProperties();
PropertyInfo[] sourcePropList = sourceObject.GetType().GetProperties();
foreach (PropertyInfo destinationPropInfo in destinationPropList)
{
foreach (PropertyInfo sourcePropInfo in sourcePropList)
{
if (sourcePropInfo.Name == destinationPropInfo.Name
&& !sourcePropInfo.GetGetMethod().IsVirtual
&& !destinationPropInfo.GetGetMethod().IsVirtual
&& (!isPropertyTypeNeedsMatch || sourcePropInfo.PropertyType == destinationPropInfo.PropertyType)
)
{
destinationPropInfo.SetValue(destinationObject, sourcePropInfo.GetValue(sourceObject, null), null);
break;
}
}
}
return destinationObject;
}
}
}