gpt4 book ai didi

c# - [显示] 属性的替换

转载 作者:太空宇宙 更新时间:2023-11-03 13:59:19 25 4
gpt4 key购买 nike

给定类:

public class Item
{
[Key]
public int ID { get; set; }

[Display]
public string Name { get; set; }

public string Observation { get; set; }
public DateTime? Done { get; set; }
}

我知道我可以通过在另一个项目中创建映射类并从 EntityTypeConfiguration 继承来定义我的 [Key] 属性和其他映射设置。

但是我如何替换 [display] 属性,这样我就不必将对 System.ComponentModel.DataAnnotations 的引用添加到我的公共(public) dll 中?

如果我还不够清楚告诉我

最佳答案

您可以创建自己的属性,然后编写一个继承 AssociatedMetadataProvider 的类,并将属性中的数据读取到 ModelMetadata 实例中。

您的类(class)将与 built-in version 相似或相同.

关于c# - [显示] 属性的替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11083711/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com