diff Source/Reflection/Extension/ExtensionList.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Source/Reflection/Extension/ExtensionList.cs	Thu Mar 27 21:46:09 2014 +0400
@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+
+namespace BLToolkit.Reflection.Extension
+{
+	public class ExtensionList : Dictionary<string,TypeExtension>
+	{
+		public new TypeExtension this[string typeName]
+		{
+			get
+			{
+				TypeExtension value;
+				lock (this)
+					return TryGetValue(typeName, out value) ? value : TypeExtension.Null;
+			}
+		}
+
+		public TypeExtension this[Type type]
+		{
+			get
+			{
+				lock (this)
+					foreach (var ext in Values)
+						if (ext.Name == type.Name || ext.Name == type.FullName)
+							return ext;
+
+				if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>))
+					return this[Nullable.GetUnderlyingType(type)];
+
+				return TypeExtension.Null;
+			}
+		}
+
+		public void Add(TypeExtension typeInfo)
+		{
+			lock (this)
+				Add(typeInfo.Name, typeInfo);
+		}
+	}
+}