84
|
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 } |