c# - 在 C# 中为模型上的属性设置默认资源类型

标签 c# resources localization

我正在寻找一种更简单/更简洁的方法来使用我的 MVC 3 模型的资源。

我现在就是这样做的(每个属性都需要被告知它使用的是哪种资源类型):

    public class ContactMessageModel:BaseModel
    {
        [Display(Name="ReplyToEmail_DisplayName", ResourceType = typeof(Res.Views_Contact))]
        public string ReplyToEmail {get; set; }

        [Display(Name = "ContactReason_DisplayName", ResourceType = typeof(Res.Views_Contact))]
        public string ContactReason { get; set; }

这可以做到吗?

这就是我想要的方式(我只想为模型定义一次资源类型):

[Display(ResourceType = typeof(Res.Views_Contact))]
public class ContactMessageModel:BaseModel
{
    [Display(Name="ReplyToEmail_DisplayName")]
    public string ReplyToEmail {get; set; }

    [Display(Name = "ContactReason_DisplayName")]            
    public string ContactReason { get; set; }

最佳答案

似乎不可能,因为属性实例需要访问它所在的属性,而 .NET 不支持。

关于c# - 在 C# 中为模型上的属性设置默认资源类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6610493/

相关文章:

c# - 使用 ServiceStack.Redis C# .Net 在 Redis 服务器中从第 m 行到第 n 行搜索数据

c# - 当我在 WPF Mvvm 中按下按钮时,如何在 DataGrid 中显示数据?

java - 类路径资源 [public] 无法解析为 URL,因为它不存在 (SPARK)

c - 有什么方法可以反编译用古代编译器构建的二进制资源文件?

ios - 如何为我的应用添加几种语言?不是描述

c# - "ref int m_a"如何让包含m a的对象不被GC回收?

c# - 等待一项任务而不等待其他任务是否可以?

Java - 如何在同一目录中没有类的情况下访问 Excel 资源?

asp.net - 如何在 ASP.Net 中创建基于本地化对象的 UI?

javascript - 使用 JavaScript 动态变量进行字符串国际化