당신은 속성과 속성의 MemberInfo
개체를 가져 반사를 사용할 필요가있다. 당신을 ViewData 편리이 경우,
// given memberInfo, controllerContext, and modelMetadata
// (see below on how to get metadata)
foreach (var attribute in memberInfo.GetCustomAttributes(typeof(ValidationAttribute), true)
{
var clientValidationAttribute = attribute as IClientValidatable;
if (clientValidationAttribute == null)
{
continue;
}
var clientValidationRules = clientValidationAttribute.GetClientValidationRules(modelMetadata, controllerContext);
// do something with the rules
}
모델 메타 데이터를 얻으려면, 당신은
ModelMetadata.FromLambdaExpression(expression, viewData)
를 호출 할 수 있습니다. 명시 적으로 ModelMetadataProvider를 호출하여 가져올 수도 있습니다. 자세한 내용이 필요한 경우 알려주십시오.
"런타임에 어댑터 가져 오기"란 무엇을 의미합니까? – Dima
아마도 최고의 단어 선택이 아닙니다. 난 그냥 DataAnnotationsModelValidatorProvider.RegisterAdapter에 의해 첨부 된 것을 검색했다. – Boomtown
내부 사전에 저장되어 있기 때문에 쉽게 얻을 수 있는지 확신 할 수 없습니다. 더 나은 옵션은 공급자에게 직접 추가 된 어댑터를 추적하는 것입니다. – VJAI