Mercurial > altnet-hispano
comparison Agendas/trunk/src/Agendas.Web/CustomModelMetadataProvider/DataAnnotationAndConventionModelMetadataProvider.cs @ 167:ea85bd893247
Ajustes menores de UI
author | nelopauselli |
---|---|
date | Sat, 06 Aug 2011 02:51:07 -0300 |
parents | c57ca21064f2 |
children | 8b0c62c255cd |
comparison
equal
deleted
inserted
replaced
166:fae2feae499e | 167:ea85bd893247 |
---|---|
14 public DataAnnotationAndConventionModelMetadataProvider(IResolverByConvention resolverByConvention) | 14 public DataAnnotationAndConventionModelMetadataProvider(IResolverByConvention resolverByConvention) |
15 { | 15 { |
16 _resolverByConvention = resolverByConvention; | 16 _resolverByConvention = resolverByConvention; |
17 } | 17 } |
18 | 18 |
19 protected override ModelMetadata CreateMetadata(IEnumerable<Attribute> attributes, Type containerType, Func<object> modelAccessor, Type modelType, string propertyName) | 19 protected override ModelMetadata CreateMetadata(IEnumerable<Attribute> attributes, Type containerType, |
20 Func<object> modelAccessor, Type modelType, string propertyName) | |
20 { | 21 { |
21 _attributeList = new List<Attribute>(attributes); | 22 _attributeList = new List<Attribute>(attributes); |
22 | 23 |
23 var modelMetadata = base.CreateMetadata(attributes, containerType, modelAccessor, modelType, propertyName); | 24 var modelMetadata = base.CreateMetadata(attributes, containerType, modelAccessor, modelType, propertyName); |
24 | 25 |
25 if (propertyName != null) | 26 if (propertyName != null) |
26 { | 27 { |
28 // Si no hay displayName asignado, lo buscamos entre los recursos | |
27 if (string.IsNullOrWhiteSpace(modelMetadata.DisplayName)) | 29 if (string.IsNullOrWhiteSpace(modelMetadata.DisplayName)) |
28 modelMetadata.DisplayName = _resolverByConvention.GetDisplayName(propertyName); | 30 modelMetadata.DisplayName = _resolverByConvention.GetDisplayName(propertyName); |
29 | 31 |
32 // Si no hay description asignado, lo buscamos entre los recursos | |
30 if (string.IsNullOrWhiteSpace(modelMetadata.Description)) | 33 if (string.IsNullOrWhiteSpace(modelMetadata.Description)) |
31 modelMetadata.Description = _resolverByConvention.GetDescription(propertyName); | 34 modelMetadata.Description = _resolverByConvention.GetDescription(propertyName); |
32 | 35 |
33 // Auto UIHint por property name. | 36 // Auto UIHint por property name. |
34 // TODO: Sería ideal chequear si existe el template antes de asignarlo, ¿cómo? | 37 // TODO: Sería ideal chequear si existe el template antes de asignarlo, ¿cómo? |
35 if (string.IsNullOrWhiteSpace(modelMetadata.TemplateHint)) | 38 if (string.IsNullOrWhiteSpace(modelMetadata.TemplateHint)) |
36 modelMetadata.TemplateHint = propertyName; | 39 modelMetadata.TemplateHint = propertyName; |
37 | 40 |
41 // Para cada validador sin texto asignado, tomamos asignamos los valores para ser buscados | |
42 // entre los recursos | |
38 var validators = _attributeList.OfType<ValidationAttribute>(); | 43 var validators = _attributeList.OfType<ValidationAttribute>(); |
39 foreach (var validator in validators) | 44 foreach (var validator in validators) |
40 { | 45 { |
41 if (string.IsNullOrWhiteSpace(validator.ErrorMessage) && | 46 if (string.IsNullOrWhiteSpace(validator.ErrorMessage) && |
42 string.IsNullOrWhiteSpace(validator.ErrorMessageResourceName)) | 47 string.IsNullOrWhiteSpace(validator.ErrorMessageResourceName)) |