annotate Agendas/trunk/src/Agendas.Web/CustomModelMetadataProvider/ResolverThroughResource.cs @ 227:11545cc95491

Mostrar todos los ponentes en el histórico
author nelopauselli
date Wed, 28 Sep 2011 08:57:34 -0300
parents ee4e699e4551
children
rev   line source
84
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
1 using System;
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
2
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
3 namespace AltNetHispano.Agendas.Web.CustomModelMetadataProvider
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
4 {
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
5 public class ResolverThroughResource<T> : IResolverByConvention
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
6 {
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
7 public string GetDisplayName(string propertyName)
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
8 {
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
9 return SearchResource(propertyName);
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
10 }
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
11
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
12 public string GetDescription(string propertyName)
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
13 {
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
14 return SearchResource(propertyName + "Description");
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
15 }
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
16
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
17 public Type ResourceType
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
18 {
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
19 get { return typeof(T); }
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
20 }
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
21
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
22 private static string SearchResource(string resourceName)
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
23 {
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
24 string displayName = null;
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
25 var resourceType = typeof(T);
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
26 var prop = resourceType.GetProperty(resourceName);
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
27 if (prop != null)
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
28 {
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
29 var value = prop.GetValue(resourceType, null);
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
30 displayName = value != null ? value.ToString() : resourceName;
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
31 }
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
32 return displayName;
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
33 }
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
34
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
35 }
ee4e699e4551 refactoring menor
nelopauselli
parents:
diff changeset
36 }