diff Agendas/trunk/src/Agendas.Web/CustomModelMetadataProvider/ResolverThroughResource.cs @ 84:ee4e699e4551

refactoring menor
author nelopauselli
date Wed, 25 May 2011 01:18:29 -0300
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Agendas/trunk/src/Agendas.Web/CustomModelMetadataProvider/ResolverThroughResource.cs	Wed May 25 01:18:29 2011 -0300
@@ -0,0 +1,36 @@
+using System;
+
+namespace AltNetHispano.Agendas.Web.CustomModelMetadataProvider
+{
+	public class ResolverThroughResource<T> : IResolverByConvention
+	{
+		public string GetDisplayName(string propertyName)
+		{
+			return SearchResource(propertyName);
+		}
+
+		public string GetDescription(string propertyName)
+		{
+			return SearchResource(propertyName + "Description");
+		}
+
+		public Type ResourceType
+		{
+			get { return typeof(T); }
+		}
+
+		private static string SearchResource(string resourceName)
+		{
+			string displayName = null;
+			var resourceType = typeof(T);
+			var prop = resourceType.GetProperty(resourceName);
+			if (prop != null)
+			{
+				var value = prop.GetValue(resourceType, null);
+				displayName = value != null ? value.ToString() : resourceName;
+			}
+			return displayName;
+		}
+
+	}
+}
\ No newline at end of file