Annotations on interfaces
Why annotations doesnt work in interfaces ?
like:
public interface IUser
{
[Required]
string FirstName { get; set; }
}
now if i made a class to implement tha开发者_如何转开发t
public partial class Customer:IUser
{
public Customer()
{
}
public string FirstName
{
get; set;
}
}
it wouldnt enforce validation unless i mark property in the class too ! so what is the point of annotate it in the interface from the first place ! ! so any idea ?
Well, the simple answer is that there is no point in annotating in the interface. As you've noted, calling Attribute.GetAttribute() (even if inherit is true) on a property does not return attributes decorated on the interface properties that your class has implemented. Presumably supporting such a facility would result in the potential for startling ambiguity when multiple interfaces are satisfied by the same implementation.
精彩评论