快速提问...
如果我在界面中添加注释...
说[必填]
我可以在属性的 C# 类中省略该符号吗?
即我可以...
interface IFoo
{
[Required]
string Bar {get; set;}
}
class Foo : IFoo
{
string Bar {get; set;}
}
或者我是否需要不将符号放入界面中并执行此操作...
interface IFoo
{
string Bar {get; set;}
}
class Foo : IFoo
{
[Required]
string Bar {get; set;}
}
将数据注释放置在界面中将不起作用。在以下链接中,有一个关于原因的解释:http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/1748587a-f13c-4dd7-9fec-c8d57014632c/
通过修改代码可以找到简单的解释,如下所示:
interface IFoo
{
[Required]
string Bar { get; set; }
}
interface IBar
{
string Bar { get; set; }
}
class Foo : IFoo, IBar
{
public string Bar { get; set; }
}
那么就不清楚是否需要 Bar 字符串,因为实现多个接口是有效的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)