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.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论