CSLA.NET 5.4.2
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
DataMap.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="DataMap.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>Defines a mapping between two sets of</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Collections.Generic;
10using Csla.Reflection;
11
12namespace Csla.Data
13{
19 public class DataMap
20 {
21 #region MapElement
22
23 internal class MemberMapping
24 {
25 public DynamicMemberHandle FromMemberHandle { get; private set; }
26 public DynamicMemberHandle ToMemberHandle { get; private set; }
27
28 public MemberMapping(DynamicMemberHandle fromMemberHandle, DynamicMemberHandle toMemberHandle)
29 {
30 FromMemberHandle = fromMemberHandle;
31 ToMemberHandle = toMemberHandle;
32 }
33 }
34
35 #endregion
36
37 private Type _sourceType;
38 private Type _targetType;
39 private List<MemberMapping> _map = new List<MemberMapping>();
40
50 public DataMap(Type sourceType, Type targetType)
51 {
52 _sourceType = sourceType;
53 _targetType = targetType;
54 }
55
66 public DataMap(Type sourceType, Type targetType, IEnumerable<string> includedPropertyNames)
67 {
68 foreach (var item in includedPropertyNames)
69 AddPropertyMapping(item, item);
70 }
71
72 internal List<MemberMapping> GetMap()
73 {
74 return _map;
75 }
76
87 public void AddPropertyMapping(string sourceProperty, string targetProperty)
88 {
89 _map.Add(new MemberMapping(
90 MethodCaller.GetCachedProperty(_sourceType, sourceProperty),
91 MethodCaller.GetCachedProperty(_targetType, targetProperty)
92 ));
93 }
94
104 public void AddFieldMapping(string sourceField, string targetField)
105 {
106 _map.Add(new MemberMapping(
107 MethodCaller.GetCachedField(_sourceType, sourceField),
108 MethodCaller.GetCachedField(_targetType, targetField)
109 ));
110 }
111
121 public void AddFieldToPropertyMapping(string sourceField, string targetProperty)
122 {
123 _map.Add(new MemberMapping(
124 MethodCaller.GetCachedField(_sourceType, sourceField),
125 MethodCaller.GetCachedProperty(_targetType, targetProperty)
126 ));
127 }
128
138 public void AddPropertyToFieldMapping(string sourceProperty, string targetField)
139 {
140 _map.Add(new MemberMapping(
141 MethodCaller.GetCachedProperty(_sourceType, sourceProperty),
142 MethodCaller.GetCachedField(_targetType, targetField)
143 ));
144 }
145 }
146}
Defines a mapping between two sets of properties/fields for use by DataMapper.
Definition: DataMap.cs:20
void AddPropertyToFieldMapping(string sourceProperty, string targetField)
Adds a property to field mapping.
Definition: DataMap.cs:138
void AddFieldToPropertyMapping(string sourceField, string targetProperty)
Adds a field to property mapping.
Definition: DataMap.cs:121
DataMap(Type sourceType, Type targetType, IEnumerable< string > includedPropertyNames)
Initializes an instance of the type.
Definition: DataMap.cs:66
void AddFieldMapping(string sourceField, string targetField)
Adds a field to field mapping.
Definition: DataMap.cs:104
void AddPropertyMapping(string sourceProperty, string targetProperty)
Adds a property to property mapping.
Definition: DataMap.cs:87
DataMap(Type sourceType, Type targetType)
Initializes an instance of the type.
Definition: DataMap.cs:50