I have a class with [Display(Name ="name")]
set in the properties, and [Table("tableName"]
in the top of the class.
Now I'm using reflection to get some information of this class and I'm wondering if somehow I can add a [Display(Name ="name")]
to the class itself.
It will be something like
[Table("MyObjectTable")]
[Display(Name ="My Class Name")] <-------------- New Annotation
public class MyObject
{
[Required]
public int Id { get; set; }
[Display(Name="My Property Name")]
public string PropertyName{ get; set; }
}
Based on @amirhossein-mehrvarzi I have used this function:
And used that in this example:
So many options :)
Based on that article I referenced heres a complete example
Declare Custom Attribute
Example of use
Example of reading attribute
Simply write a
static
function like this:And use that like this:
There is already an attribute for that in .Net: http://msdn.microsoft.com/en-us/library/system.componentmodel.displaynameattribute.aspx . And yes, you can use it on both: properties and classes (check an
AttributeUsageAttribute
in Syntax section)