comparison Source/Reflection/MetadataProvider/MetadataProviderList.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f990fcb411a9
1 using System;
2 using System.Collections.Generic;
3
4 namespace BLToolkit.Reflection.MetadataProvider
5 {
6 using DataAccess;
7 using Extension;
8 using Mapping;
9
10 public class MetadataProviderList : MetadataProviderBase
11 {
12 #region Init
13
14 public MetadataProviderList()
15 {
16 AddProvider(new ExtensionMetadataProvider());
17 AddProvider(new AttributeMetadataProvider());
18 #if !SILVERLIGHT
19 AddProvider(new LinqMetadataProvider());
20 #endif
21 }
22
23 private readonly List<MetadataProviderBase> _list = new List<MetadataProviderBase>(3);
24
25 #endregion
26
27 #region Provider Support
28
29 public override void AddProvider(MetadataProviderBase provider)
30 {
31 _list.Add(provider);
32 }
33
34 public override void InsertProvider(int index, MetadataProviderBase provider)
35 {
36 _list.Insert(index, provider);
37 }
38
39 public override MetadataProviderBase[] GetProviders()
40 {
41 return _list.ToArray();
42 }
43
44 #endregion
45
46 #region GetFieldName
47
48 public override string GetFieldName(TypeExtension typeExtension, MemberAccessor member, out bool isSet)
49 {
50 foreach (var p in _list)
51 {
52 var name = p.GetFieldName(typeExtension, member, out isSet);
53
54 if (isSet)
55 return name;
56 }
57
58 return base.GetFieldName(typeExtension, member, out isSet);
59 }
60
61 #endregion
62
63 #region GetFieldStorage
64
65 public override string GetFieldStorage(TypeExtension typeExtension, MemberAccessor member, out bool isSet)
66 {
67 foreach (var p in _list)
68 {
69 var name = p.GetFieldStorage(typeExtension, member, out isSet);
70
71 if (isSet)
72 return name;
73 }
74
75 return base.GetFieldStorage(typeExtension, member, out isSet);
76 }
77
78 #endregion
79
80 #region GetInheritanceDiscriminator
81
82 public override bool GetInheritanceDiscriminator(TypeExtension typeExtension, MemberAccessor member, out bool isSet)
83 {
84 foreach (var p in _list)
85 {
86 var value = p.GetInheritanceDiscriminator(typeExtension, member, out isSet);
87
88 if (isSet)
89 return value;
90 }
91
92 return base.GetInheritanceDiscriminator(typeExtension, member, out isSet);
93 }
94
95 #endregion
96
97 #region EnsureMapper
98
99 public override void EnsureMapper(TypeAccessor typeAccessor, MappingSchema mappingSchema, EnsureMapperHandler handler)
100 {
101 foreach (var p in _list)
102 p.EnsureMapper(typeAccessor, mappingSchema, handler);
103 }
104
105 #endregion
106
107 #region GetMapIgnore
108
109 public override bool GetMapIgnore(TypeExtension typeExtension, MemberAccessor member, out bool isSet)
110 {
111 foreach (var p in _list)
112 {
113 var ignore = p.GetMapIgnore(typeExtension, member, out isSet);
114
115 if (isSet)
116 return ignore;
117 }
118
119 return base.GetMapIgnore(typeExtension, member, out isSet);
120 }
121
122 #endregion
123
124 #region GetMapField
125
126 public override MapFieldAttribute GetMapField(TypeExtension typeExtension, MemberAccessor member, out bool isSet)
127 {
128 foreach (var p in _list)
129 {
130 var attr = p.GetMapField(typeExtension, member, out isSet);
131
132 if (attr != null)
133 return attr;
134 }
135
136 return base.GetMapField(typeExtension, member, out isSet);
137 }
138
139 #endregion
140
141 #region GetDbType
142
143 [CLSCompliant(false)]
144 public override DbTypeAttribute GetDbType(TypeExtension typeExtension, MemberAccessor member, out bool isSet)
145 {
146 foreach (var p in _list)
147 {
148 var attr = p.GetDbType(typeExtension, member, out isSet);
149
150 if (attr != null)
151 return attr;
152 }
153
154 return base.GetDbType(typeExtension, member, out isSet);
155 }
156
157 #endregion
158
159 #region GetPrimaryKey
160
161 public override PrimaryKeyAttribute GetPrimaryKey(TypeExtension typeExtension, MemberAccessor member, out bool isSet)
162 {
163 foreach (var p in _list)
164 {
165 var attr = p.GetPrimaryKey(typeExtension, member, out isSet);
166
167 if (attr != null)
168 return attr;
169 }
170
171 return base.GetPrimaryKey(typeExtension, member, out isSet);
172 }
173
174 #endregion
175
176 #region GetTrimmable
177
178 public override bool GetTrimmable(TypeExtension typeExtension, MemberAccessor member, out bool isSet)
179 {
180 if (member.Type == typeof(string))
181 {
182 foreach (var p in _list)
183 {
184 var trimmable = p.GetTrimmable(typeExtension, member, out isSet);
185
186 if (isSet)
187 return trimmable;
188 }
189 }
190
191 return base.GetTrimmable(typeExtension, member, out isSet);
192 }
193
194 #endregion
195
196 #region GetMapValues
197
198 public override MapValue[] GetMapValues(TypeExtension typeExtension, MemberAccessor member, out bool isSet)
199 {
200 foreach (var p in _list)
201 {
202 var value = p.GetMapValues(typeExtension, member, out isSet);
203
204 if (isSet)
205 return value;
206 }
207
208 return base.GetMapValues(typeExtension, member, out isSet);
209 }
210
211 public override MapValue[] GetMapValues(TypeExtension typeExt, Type type, out bool isSet)
212 {
213 foreach (var p in _list)
214 {
215 var value = p.GetMapValues(typeExt, type, out isSet);
216
217 if (isSet)
218 return value;
219 }
220
221 return base.GetMapValues(typeExt, type, out isSet);
222 }
223
224 #endregion
225
226 #region GetDefaultValue
227
228 public override object GetDefaultValue(MappingSchema mappingSchema, TypeExtension typeExtension, MemberAccessor member, out bool isSet)
229 {
230 foreach (var p in _list)
231 {
232 var value = p.GetDefaultValue(mappingSchema, typeExtension, member, out isSet);
233
234 if (isSet)
235 return value;
236 }
237
238 return base.GetDefaultValue(mappingSchema, typeExtension, member, out isSet);
239 }
240
241 public override object GetDefaultValue(MappingSchema mappingSchema, TypeExtension typeExtension, Type type, out bool isSet)
242 {
243 foreach (var p in _list)
244 {
245 var value = p.GetDefaultValue(mappingSchema, typeExtension, type, out isSet);
246
247 if (isSet)
248 return value;
249 }
250
251 return base.GetDefaultValue(mappingSchema, typeExtension, type, out isSet);
252 }
253
254 #endregion
255
256 #region GetNullable
257
258 public override bool GetNullable(MappingSchema mappingSchema, TypeExtension typeExtension, MemberAccessor member, out bool isSet)
259 {
260 foreach (var p in _list)
261 {
262 var value = p.GetNullable(mappingSchema, typeExtension, member, out isSet);
263
264 if (isSet)
265 return value;
266 }
267
268 return base.GetNullable(mappingSchema, typeExtension, member, out isSet);
269 }
270
271 #endregion
272
273 #region GetLazyInstance
274
275 public override bool GetLazyInstance(MappingSchema mappingSchema, TypeExtension typeExtension, MemberAccessor member, out bool isSet)
276 {
277 foreach (var p in _list)
278 {
279 var value = p.GetLazyInstance(mappingSchema, typeExtension, member, out isSet);
280
281 if (isSet)
282 return value;
283 }
284
285 return base.GetLazyInstance(mappingSchema, typeExtension, member, out isSet);
286 }
287
288 #endregion
289
290 #region GetNullValue
291
292 public override object GetNullValue(MappingSchema mappingSchema, TypeExtension typeExtension, MemberAccessor member, out bool isSet)
293 {
294 foreach (var p in _list)
295 {
296 var value = p.GetNullValue(mappingSchema, typeExtension, member, out isSet);
297
298 if (isSet)
299 return value;
300 }
301
302 return base.GetNullValue(mappingSchema, typeExtension, member, out isSet);
303 }
304
305 #endregion
306
307 #region GetDbName
308
309 public override string GetDatabaseName(Type type, ExtensionList extensions, out bool isSet)
310 {
311 foreach (var p in _list)
312 {
313 var value = p.GetDatabaseName(type, extensions, out isSet);
314
315 if (isSet)
316 return value;
317 }
318
319 return base.GetDatabaseName(type, extensions, out isSet);
320 }
321
322 #endregion
323
324 #region GetOwnerName
325
326 public override string GetOwnerName(Type type, ExtensionList extensions, out bool isSet)
327 {
328 foreach (var p in _list)
329 {
330 var value = p.GetOwnerName(type, extensions, out isSet);
331
332 if (isSet)
333 return value;
334 }
335
336 return base.GetOwnerName(type, extensions, out isSet);
337 }
338
339 #endregion
340
341 #region GetTableName
342
343 public override string GetTableName(Type type, ExtensionList extensions, out bool isSet)
344 {
345 foreach (var p in _list)
346 {
347 var value = p.GetTableName(type, extensions, out isSet);
348
349 if (isSet)
350 return value;
351 }
352
353 return base.GetTableName(type, extensions, out isSet);
354 }
355
356 #endregion
357
358 #region GetPrimaryKeyOrder
359
360 public override int GetPrimaryKeyOrder(Type type, TypeExtension typeExt, MemberAccessor member, out bool isSet)
361 {
362 foreach (var p in _list)
363 {
364 var value = p.GetPrimaryKeyOrder(type, typeExt, member, out isSet);
365
366 if (isSet)
367 return value;
368 }
369
370 return base.GetPrimaryKeyOrder(type, typeExt, member, out isSet);
371 }
372
373 #endregion
374
375 public override string GetSequenceName(TypeExtension typeExtension, MemberAccessor member, out bool isSet)
376 {
377 foreach (var p in _list)
378 {
379 var value = p.GetSequenceName(typeExtension, member, out isSet);
380
381 if (isSet)
382 return value;
383 }
384
385 return base.GetSequenceName(typeExtension, member, out isSet);
386 }
387
388 #region GetNonUpdatableFlag
389
390 public override NonUpdatableAttribute GetNonUpdatableAttribute(Type type, TypeExtension typeExt, MemberAccessor member, out bool isSet)
391 {
392 foreach (var p in _list)
393 {
394 var value = p.GetNonUpdatableAttribute(type, typeExt, member, out isSet);
395
396 if (isSet)
397 return value;
398 }
399
400 return base.GetNonUpdatableAttribute(type, typeExt, member, out isSet);
401 }
402
403 #endregion
404
405 #region GetSqlIgnore
406
407 public override bool GetSqlIgnore(TypeExtension typeExtension, MemberAccessor member, out bool isSet)
408 {
409 foreach (var p in _list)
410 {
411 var ignore = p.GetSqlIgnore(typeExtension, member, out isSet);
412
413 if (isSet)
414 return ignore;
415 }
416
417 return base.GetSqlIgnore(typeExtension, member, out isSet);
418 }
419
420 #endregion
421
422 #region GetRelations
423
424 public override List<MapRelationBase> GetRelations(MappingSchema schema, ExtensionList typeExt, Type master, Type slave, out bool isSet)
425 {
426 foreach (var p in _list)
427 {
428 var relations = p.GetRelations(schema, typeExt, master, slave, out isSet);
429
430 if (isSet)
431 return relations;
432 }
433
434 return base.GetRelations(schema, typeExt, master, slave, out isSet);
435 }
436
437 #endregion
438
439 #region GetAssociation
440
441 public override Association GetAssociation(TypeExtension typeExtension, MemberAccessor member)
442 {
443 foreach (var p in _list)
444 {
445 var attr = p.GetAssociation(typeExtension, member);
446
447 if (attr != null)
448 return attr;
449 }
450
451 return base.GetAssociation(typeExtension, member);
452 }
453
454 #endregion
455
456 #region GetInheritanceMapping
457
458 public override InheritanceMappingAttribute[] GetInheritanceMapping(Type type, TypeExtension typeExtension)
459 {
460 foreach (var p in _list)
461 {
462 var attrs = p.GetInheritanceMapping(type, typeExtension);
463
464 if (attrs.Length > 0)
465 return attrs;
466 }
467
468 return base.GetInheritanceMapping(type, typeExtension);
469 }
470
471 #endregion
472 }
473 }