Repository navigation
Expand file tree
/
Copy pathINodeMappingExpression.cs
More file actions
286 lines (271 loc) · 12.7 KB
/
Copy pathINodeMappingExpression.cs
File metadata and controls
286 lines (271 loc) · 12.7 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
using System;
using System.Linq.Expressions;
using umbraco.NodeFactory;
using System.Collections.Generic;
using uComponents.Mapping.Property;
namespace uComponents.Mapping
{
/// <summary>
/// Fluent configuration for an <see cref="INodeMappingEngine"/> mapping
/// </summary>
/// <typeparam name="TDestination">The destination model type.</typeparam>
public interface INodeMappingExpression<TDestination>
{
/// <summary>
/// Sets a mapping for a default <c>Node</c> property (such as "Name" or "CreateDate").
/// </summary>
/// <typeparam name="TSourceProperty">
/// The type of the source property. For instance, "Name" will be a <c>string</c>,
/// and "CreateDate" will be a <c>DateTime</c>.
/// </typeparam>
/// <typeparam name="TDestinationProperty">
/// The type of the destination property. This should be assignable to
/// <typeparamref name="TSourceProperty"/>.
/// </typeparam>
/// <param name="destinationProperty">The property to map to.</param>
/// <param name="nodeProperty">The node property to map from.</param>
/// <param name="mapping">
/// A simple mapping for the source property value, e.g. x => x.Trim()
/// </param>
INodeMappingExpression<TDestination> DefaultProperty<TSourceProperty, TDestinationProperty>(
Expression<Func<TDestination, TDestinationProperty>> destinationProperty,
Expression<Func<Node, TSourceProperty>> nodeProperty,
Func<TSourceProperty, TDestinationProperty> mapping
);
/// <summary>
/// Sets the node property alias to be used for a non-relational model
/// property, using the default mapping. This property will not require an include.
///
/// Use this method only for properties mapped from a property alias - use
/// <see cref="DefaultProperty"/> for a default <c>Node</c> property.
/// </summary>
/// <param name="destinationProperty">The property to map to.</param>
/// <param name="propertyAlias">The new property alias to use.</param>
INodeMappingExpression<TDestination> BasicProperty(
Expression<Func<TDestination, object>> destinationProperty,
string propertyAlias
);
/// <summary>
/// Sets a non-relational mapping for a model property. This property
/// will not require an include.
/// </summary>
/// <typeparam name="TSourceProperty">
/// The desired type to inject into <paramref name="mapping"/> (will be
/// converted if necessary). This should be a simple type like <c>string</c>,
/// <c>int?</c> or an enum.
/// </typeparam>
/// <param name="destinationProperty">The property to map to.</param>
/// <param name="mapping">
/// Maps the node property to the model property.
/// </param>
/// <param name="propertyAlias">The property alias to map from. Optional.</param>
/// <example>
/// <code>
/// uMapper.CreateMap{Dog}()
/// .BasicProperty{string}(
/// x => x.CollarId,
/// collarId => collarId.Trim() // trim whitespace
/// );
///
/// Simply trims the source property value
/// </code>
/// </example>
INodeMappingExpression<TDestination> BasicProperty<TSourceProperty>(
Expression<Func<TDestination, object>> destinationProperty,
BasicPropertyMapping<TSourceProperty> mapping,
string propertyAlias = null
);
/// <summary>
/// Sets the node property alias to be used for a single relationship
/// property, using the default mapping. This property will require an include.
/// </summary>
/// <param name="destinationProperty">The property to map to.</param>
/// <param name="propertyAlias">The new property alias to use.</param>
INodeMappingExpression<TDestination> SingleProperty(
Expression<Func<TDestination, object>> destinationProperty,
string propertyAlias
);
/// <summary>
/// Sets a mapping for a single node to be used for the model
/// property, based on the identity of the node being mapped.
/// This property will require an include.
/// </summary>
/// <param name="destinationProperty">The property to map to.</param>
/// <param name="mapping">
/// A mapping which take the ID of the node being mapped, and returns
/// the ID of the node to map to the property.
/// </param>
INodeMappingExpression<TDestination> SingleProperty(
Expression<Func<TDestination, object>> destinationProperty,
Func<int, int?> mapping
);
/// <summary>
/// Sets a mapping for a single node to be used for the model
/// property, based on the value of a node property.
/// This property will require an include.
/// </summary>
/// <typeparam name="TSourceProperty">
/// The desired type to inject into <paramref name="mapping"/> (will be
/// converted if necessary). This should be a simple type like <c>string</c> or
/// <c>int?</c>.
/// </typeparam>
/// <param name="destinationProperty">The property to map to.</param>
/// <param name="mapping">
/// A mapping which takes the value of a node property, and returns
/// the ID of the node to map to the property.
/// </param>
/// <param name="propertyAlias">
/// An optional node property alias override.
/// </param>
/// <example>
/// <code>
/// // "SearchAllDogsForId" is an external method which searches through all
/// // dogs based on a name property.
///
/// uMapper.CreateMap{Dog}()
/// .SingleProperty{string}(
/// x => x.BestFriend,
/// name => SearchAllDogsForId(name), // must return an `int?`
/// "bestFriendName" // required as "BestFriend" !~ "bestFriendName"
/// );
///
/// </code>
/// </example>
INodeMappingExpression<TDestination> SingleProperty<TSourceProperty>(
Expression<Func<TDestination, object>> destinationProperty,
SinglePropertyMapping<TSourceProperty> mapping,
string propertyAlias = null
);
/// <summary>
/// Sets the node property alias to be used for a collection relationship
/// property, using the default mapping. This property will require an include.
/// </summary>
/// <param name="destinationProperty">The property to map to.</param>
/// <param name="propertyAlias">The new property alias to use.</param>
INodeMappingExpression<TDestination> CollectionProperty(
Expression<Func<TDestination, object>> destinationProperty,
string propertyAlias
);
/// <summary>
/// Sets a mapping for a collection node to be used for the model
/// property, based on the identity of the node being mapped.
/// This property will require an include.
/// </summary>
/// <param name="destinationProperty">The property to map to.</param>
/// <param name="mapping">
/// A mapping which take the ID of the node being mapped, and returns
/// the collection of IDs.
/// </param>
INodeMappingExpression<TDestination> CollectionProperty(
Expression<Func<TDestination, object>> destinationProperty,
Func<int, IEnumerable<int>> mapping
);
/// <summary>
/// Sets a mapping for a collection to be used for the model
/// property. This property will require an include.
/// </summary>
/// <typeparam name="TSourceProperty">
/// The desired type to inject into <paramref name="mapping"/> (will be
/// converted if necessary). This should be a simple type like <c>string</c>,
/// <c>int?</c> or <c>int[]</c>.
/// </typeparam>
/// <param name="destinationProperty">The property to map to.</param>
/// <param name="mapping">
/// A mapping which retrieves the IDs of the items in the collection.
/// </param>
/// <param name="propertyAlias">
/// An optional node property alias override.
/// </param>
/// <example>
/// <code>
/// // This will restrict the number of favourite treats mapped to 3.
///
/// uMapper.CreateMap{Dog}()
/// .CollectionProperty{int[]}(
/// x => x.FavouriteTreats,
/// ids => ids.Take(3)
/// );
/// </code>
/// </example>
INodeMappingExpression<TDestination> CollectionProperty<TSourceProperty>(
Expression<Func<TDestination, object>> destinationProperty,
CollectionPropertyMapping<TSourceProperty> mapping,
string propertyAlias = null
);
/// <summary>
/// Sets a custom mapping to be used for a model property.
/// </summary>
/// <param name="destinationProperty">The property to map to.</param>
/// <param name="mapping">
/// A mapping which retrieves the value of the property.
/// </param>
/// <param name="requiresInclude">
/// Whether the property requires an explicit include.
/// </param>
/// <param name="allowCaching">
/// If set to true, the result of <paramref name="mapping"/> will be cached.
/// While caching is disabled on the <see cref="INodeMappingEngine"/>, no caching will occur.
/// </param>
INodeMappingExpression<TDestination> CustomProperty(
Expression<Func<TDestination, object>> destinationProperty,
CustomPropertyMapping mapping,
bool requiresInclude,
bool allowCaching
);
/// <summary>
/// Removes the mapping for a property, if any exists.
/// </summary>
/// <param name="destinationProperty">The property on the model to NOT map to</param>
INodeMappingExpression<TDestination> RemoveMappingForProperty(
Expression<Func<TDestination, object>> destinationProperty
);
#region Legacy
/// <summary>
/// Sets a custom mapping to be used for a the model property.
/// </summary>
/// <param name="destinationProperty">The member of the destination model
/// to map to.</param>
/// <param name="propertyMapping">
/// The new mapping function. Arguments are the node being mapped,
/// and an array of paths relative to the property being mapped
/// (when mapping a relationship).
/// </param>
/// <param name="requiresInclude">
/// Whether the property requires an explicit include to be mapped.
/// </param>
[Obsolete("Use BasicProperty, SingleProperty, CollectionProperty or CustomProperty instead")]
INodeMappingExpression<TDestination> ForProperty<TProperty>(
Expression<Func<TDestination, TProperty>> destinationProperty,
Func<Node, string[], object> propertyMapping,
bool requiresInclude
);
/// <summary>
/// Sets a custom mapping to be used for a the model property.
/// </summary>
/// <param name="destinationProperty">The member of the destination model
/// to map to.</param>
/// <param name="propertyMapping">
/// The new mapping function.
/// </param>
/// <param name="isRelationship">Whether the property should be deemed a relationship
/// or not.</param>
[Obsolete("Use BasicProperty, SingleProperty, CollectionProperty or CustomProperty instead")]
INodeMappingExpression<TDestination> ForProperty<TProperty>(
Expression<Func<TDestination, TProperty>> destinationProperty,
Func<Node, object> propertyMapping,
bool isRelationship
);
/// <summary>
/// Sets a custom property alias to be set for a the model property.
/// </summary>
/// <param name="destinationProperty">The member of the destination model
/// to map to.</param>
/// <param name="nodeTypeAlias">The property alias to map from.</param>
[Obsolete("Use BasicProperty, SingleProperty or CollectionProperty instead")]
INodeMappingExpression<TDestination> ForProperty<TProperty>(
Expression<Func<TDestination, TProperty>> destinationProperty,
string nodeTypeAlias
);
#endregion
}
}