Mercurial > altnet-hispano
comparison 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 |
comparison
equal
deleted
inserted
replaced
83:7e9ffde4022d | 84:ee4e699e4551 |
---|---|
1 using System; | |
2 | |
3 namespace AltNetHispano.Agendas.Web.CustomModelMetadataProvider | |
4 { | |
5 public class ResolverThroughResource<T> : IResolverByConvention | |
6 { | |
7 public string GetDisplayName(string propertyName) | |
8 { | |
9 return SearchResource(propertyName); | |
10 } | |
11 | |
12 public string GetDescription(string propertyName) | |
13 { | |
14 return SearchResource(propertyName + "Description"); | |
15 } | |
16 | |
17 public Type ResourceType | |
18 { | |
19 get { return typeof(T); } | |
20 } | |
21 | |
22 private static string SearchResource(string resourceName) | |
23 { | |
24 string displayName = null; | |
25 var resourceType = typeof(T); | |
26 var prop = resourceType.GetProperty(resourceName); | |
27 if (prop != null) | |
28 { | |
29 var value = prop.GetValue(resourceType, null); | |
30 displayName = value != null ? value.ToString() : resourceName; | |
31 } | |
32 return displayName; | |
33 } | |
34 | |
35 } | |
36 } |