Sayfalar

29 Ağustos 2019 Perşembe

Attributes Usage()


Attribute Usage ile tanımlanan Att. nerelerde kullanılabileceğini belirleriz.

Örn: Sadece classlarda kullanılmak üzere tanımlanmış olan MyRequired Attribute, Attribute Usage() > Attribute.Targets.Class verildiği için Customer sınıfındaki propertieslerde kullanıldığında uyarı aldık.

[MyTable("Customer")]
public class Customer : IEntity
{
    public int Id { getset; }
    [MyRequired]
    public string FirstName { getset; }
    [MyRequired]
    public string LastName { getset; }
    public int Age { getset; }
 
}
 
 
[AttributeUsage(AttributeTargets.Class)]
class MyRequiredAttribute:Attribute
{
 
} 


Birden fazla Usage() alanı tanımlayabiliriz

[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
class MyRequiredAttribute:Attribute
{
 
}



MVC LOADING TOO SLOW ISSUE