I created a custom attribute.
public class DisplayAttribute : Attribute
{
public bool IsDisplay;
public string DisplayName;
public DisplayAttribute()
{
IsDisplay = true;
DisplayName = string.Empty;
}
public DisplayAttribute(bool isDisplay)
{
IsDisplay = isDisplay;
DisplayName = string.Empty;
}
public DisplayAttribute(string displayName)
{
IsDisplay = true;
DisplayName = displayName;
}
public DisplayAttribute(bool isDisplay,string displayName)
{
IsDisplay = isDisplay;
DisplayName = displayName;
}
}
My motive for creating this attribute was to restrict the property so that it appears when I retrieve a list of properties from a specific class
Here is my class
public class tblContacts : Connection
{
[Display(false)]
public int ContactId { get; set; }
[Display(true,"Category Name")]
public string CategoryName { get; set; }
[Display("First Name")]
public string FirstName { get; set; }
}
but when I execute the following instruction
tblContacts obj=new tblContacts();
obj.GetType().GetProperties();
he does not satisfy the motive
source
share