0
|
1 using System;
|
|
2 using System.Collections.Generic;
|
|
3
|
|
4 namespace BLToolkit.Reflection.Extension
|
|
5 {
|
|
6 public class ExtensionList : Dictionary<string,TypeExtension>
|
|
7 {
|
|
8 public new TypeExtension this[string typeName]
|
|
9 {
|
|
10 get
|
|
11 {
|
|
12 TypeExtension value;
|
|
13 lock (this)
|
|
14 return TryGetValue(typeName, out value) ? value : TypeExtension.Null;
|
|
15 }
|
|
16 }
|
|
17
|
|
18 public TypeExtension this[Type type]
|
|
19 {
|
|
20 get
|
|
21 {
|
|
22 lock (this)
|
|
23 foreach (var ext in Values)
|
|
24 if (ext.Name == type.Name || ext.Name == type.FullName)
|
|
25 return ext;
|
|
26
|
|
27 if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>))
|
|
28 return this[Nullable.GetUnderlyingType(type)];
|
|
29
|
|
30 return TypeExtension.Null;
|
|
31 }
|
|
32 }
|
|
33
|
|
34 public void Add(TypeExtension typeInfo)
|
|
35 {
|
|
36 lock (this)
|
|
37 Add(typeInfo.Name, typeInfo);
|
|
38 }
|
|
39 }
|
|
40 }
|