验证属性
我有一个抽象类,它从某个接口继承属性。因此无法验证属性支持字段。那么您知道如何实现自定义属性来验证属性吗?
您获得了抽象类 Collaborator,
public abstract class Collaborator
{
}
然后从某些接口继承它:
interface IPersonInformation
{
String FirstName { get; set; }
String LastName { get; set; }
}
interface IRecruitmentInformation
{
DateTime RecruitmentDate { get; set; }
}
///
public abstract class Collaborator : IPersonInformation, IRecruitmentInformation
{
public String FirstName { get; set; }
public String LastName { get; set; }
public DateTime RecruitmentDate { get; set; }
}
因此您无法使用其支持字段来验证 Collaborator
类中的属性 - 它们是自动的。 那么有没有办法使用属性上的属性来验证名称呢?
I have an abstract class, which inherits a property from some interface. So it is impossible to validate the property backing field. So do you have any idea on how to implement custom attributes to validate properties?
You got abstract class Collaborator,
public abstract class Collaborator
{
}
Then you inherit it from some interfaces:
interface IPersonInformation
{
String FirstName { get; set; }
String LastName { get; set; }
}
interface IRecruitmentInformation
{
DateTime RecruitmentDate { get; set; }
}
///
public abstract class Collaborator : IPersonInformation, IRecruitmentInformation
{
public String FirstName { get; set; }
public String LastName { get; set; }
public DateTime RecruitmentDate { get; set; }
}
So you cannot validate properties in Collaborator
class using their backing field - they are automatic.
So is there a way to use attributes on the properties to validate name?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
作为实现接口的一种方式应该可以很好地工作。我想不出使用属性来实现此目的的更好方法。
Should work fine as a way of implementing your interfaces. I cannot think of a better way of achieving this using attributes.