这可能是一个非常愚蠢的问题,但我似乎找不到答案。在我的模型类中,我总是需要添加几行using语句 - 例如
using System.ComponentModel.DataAnnotations
有没有办法在每个模型类中自动包含该命名空间,所以我不必每次都输入它?
由于
答案 0 :(得分:3)
您的问题是similar to this one该问题的答案是您有4种选择:
答案 1 :(得分:0)
要实现这一点,您需要创建自定义Visual Studio项目模板:
答案 2 :(得分:0)
此命名空间用于验证属性。我倾向于在我的班级中写出一个属性,并添加一个属性,例如RequiredAttribute
。
我输入[Required
,然后d
Visual Studio在该行的底部放置一个小方块。按 Ctrl + 。,您将获得一个上下文菜单,为您添加所需的using
语句。因此,您无需手动输入。