// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ModelBinding.Validation
{
///
/// An implementation of which understands data annotation attributes.
///
/// The type of the attribute.
public abstract class DataAnnotationsClientModelValidator : IClientModelValidator
where TAttribute : ValidationAttribute
{
///
/// Create a new instance of .
///
/// The instance to validate.
public DataAnnotationsClientModelValidator(TAttribute attribute)
{
Attribute = attribute;
}
///
/// Gets the type of the associated with this instance.
///
public TAttribute Attribute
{
get;
}
///
public abstract IEnumerable GetClientValidationRules(
ClientModelValidationContext context);
///
/// Gets the error message formatted using the .
///
/// The associated with the model annotated with
/// .
/// Formatted error string.
protected virtual string GetErrorMessage([NotNull] ModelMetadata modelMetadata)
{
return Attribute.FormatErrorMessage(modelMetadata.GetDisplayName());
}
}
}