C# 数据类型和注释属性重用
是否可以创建一个类或类似于C# 数据类型和注释属性重用,c#,C#,是否可以创建一个类或类似于string的东西,它可以用于具有数据注释属性的差异模型 型号代码: public class Model1 { public mytype type1 { get; set; } public string type2 { get; set; } } public class Model2 { public mytype type1 { get; set; } public string type2 { get; set; } }
string
的东西,它可以用于具有数据注释属性的差异模型
型号代码:
public class Model1
{
public mytype type1 { get; set; }
public string type2 { get; set; }
}
public class Model2
{
public mytype type1 { get; set; }
public string type2 { get; set; }
}
基类
public class mytype
{
[StringLength(20)]
public string mytype { get; set; }
}
您可以创建自己的数据批注。这里有一个链接解释了如何做到这一点:试着解释一下你更想要什么,例如使用一些代码。我不知道你到底想达到什么目的。你是想限制
mytype
不超过20个字符还是什么?你问题的正确答案是“是”。如果您需要更有用、更详细的答案,您需要问一个更有用、更详细的问题。我希望属性有一个标准或中心类来控制数据注释,而不是每次都键入它。注释不仅仅是字符串长度和其他内容,如显示格式等。谢谢。在其他地方发布链接时要小心。如果这篇文章从网站上删除,你的答案将不再有效!!谢谢是否可以定义为类型?因此,它可以用作参数。类似于公共函数1(mytype类型1)。