Mercurial > altnet-hispano
diff Agendas/trunk/src/Agendas.Web/EditorDefaultExtensions.cs @ 155:23aaf98b8377
Generalizando editores en EditorDefault basando los textos en recursos
author | Nelo@Guinea.neluz.int |
---|---|
date | Wed, 03 Aug 2011 09:38:23 -0300 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Agendas/trunk/src/Agendas.Web/EditorDefaultExtensions.cs Wed Aug 03 09:38:23 2011 -0300 @@ -0,0 +1,36 @@ +using System.Web; +using System.Web.Mvc; + +namespace AltNetHispano.Agendas.Web +{ + public static class EditorDefaultExtensions + { + public static HtmlString GetTitleForModel<T>(this HtmlHelper<T> helper) + { + return new HtmlString(SearchResource(helper.ViewData.Model.GetType().Name + "Title")); + } + + public static HtmlString GetDescriptionForModel<T>(this HtmlHelper<T> helper) + { + return new HtmlString(SearchResource(helper.ViewData.Model.GetType().Name + "Description")); + } + + public static HtmlString GetLegendForModel<T>(this HtmlHelper<T> helper) + { + return new HtmlString(SearchResource(helper.ViewData.Model.GetType().Name + "Legend")); + } + + private static string SearchResource(string resourceName) + { + string displayName = null; + var resourceType = typeof(Resources.Properties.LayoutResources); + var prop = resourceType.GetProperty(resourceName); + if (prop != null) + { + var value = prop.GetValue(resourceType, null); + displayName = value != null ? value.ToString() : resourceName; + } + return displayName ?? string.Empty; + } + } +} \ No newline at end of file