Реализация пользовательского DataAnnotationsModelMetadataProvider
в ASP.NET MVC2.
Предполагая, что объект который отображается, выглядит следующим образом:
- Contact : IUpdateable
- Name: string
- ContactType: (Lead, Prospect, Customer)
, а метод ниже находится в контексте Contact.ContactType
, что означает, что:
meta.PropertyName == "ContactType"
meta.ContainerType = = typeof (Контакт)
meta. Model == ContactType.Lead
(код под вопросом:)
protected override ModelMetadata CreateMetadata(IEnumerable<Attribute> attributes,
Type containerType,
Func<object> modelAccessor,
Type modelType, string propertyName) {
var containerInstance = meta.NotSureWhatGoesHere as IUpdateable;
meta.IsReadOnly = containerInstance != null && containerInstance.CanBeUpdated(meta.PropertyName);
}
Вопрос : Как я могу получить экземпляр контакта из метаданных? (замените NotSureWhatGoesHere
правильным)?
Спасибо.