Cap*_*lly 8 c# data-annotations
快速问题......
如果我在界面中添加一个符号......
说[必填]
我可以在C#类中省略该属性的符号吗?
即我可以......
Interface IFoo
{
[Required]
string Bar {get; set;}
}
Class Foo : IFoo
{
string Bar {get; set;}
}
Run Code Online (Sandbox Code Playgroud)
或者我是否需要不将符号放在界面中并执行此操作...
Interface IFoo
{
string Bar {get; set;}
}
Class Foo : IFoo
{
[Required]
string Bar {get; set;}
}
Run Code Online (Sandbox Code Playgroud)
在界面中放置数据注释将不起作用.在以下链接中有一个解释为什么: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; }
}
Run Code Online (Sandbox Code Playgroud)
然后不清楚Bar字符串是否是必需的,因为它实现多个接口是有效的.
| 归档时间: |
|
| 查看次数: |
1530 次 |
| 最近记录: |