提问人:Erwin van der Valk 提问时间:11/2/2023 更新时间:11/2/2023 访问量:6
是否可以在没有 aspnet mvc 的情况下使用 System.ComponentModel.DataAnnotations 的翻译?
Is it possible to use translations for System.ComponentModel.DataAnnotations without aspnet mvc?
问:
我在控制台应用程序中使用数据注释验证。我想在使用默认属性时翻译错误消息(因此不指定特定的资源类型/键)。
我已经看到一些使用 aspnet MVC 执行此操作的示例(具有不同程度的成功),但在我的示例中,我没有使用 mvc。
这是一个单元测试,显示了我正在尝试执行的操作:
[Fact]
public void Test1()
{
CultureInfo.CurrentUICulture = new CultureInfo("nl-NL");
var objectWithValidation = new ObjectWithValidation();
var validationContext = new ValidationContext(objectWithValidation);
var validationResults = new List<ValidationResult>();
Validator.TryValidateObject(objectWithValidation, validationContext, validationResults, true);
// Validation results should be in dutch, but they are in en-US
}
public class ObjectWithValidation
{
[Required()]
public string Name { get; set; }
}
答: 暂无答案
评论