C # Get custom features on the class through reflection

Source: Internet
Author: User

The following is what I used in my previous project. At that time, I used custom features to include configurable features when exporting an excel report. The specific excel operation is not the focus of this article, and this article will not explain it more. The following is an example to illustrate how to obtain custom features through reflection. The example only uses custom features for classes and attributes. Readers can reasonably use custom features based on actual project requirements.

1. Implement object custom features and inherit from the Attribute Class

Code
/// <Summary>
/// Custom feature attributes or classes can be inherited
/// </Summary>
[AttributeUsage (AttributeTargets. Property | AttributeTargets. Class, Inherited = true)]
Public class EnitityMappingAttribute: Attribute
{
Private string tableName;
/// <Summary>
/// Actual table name of the object
/// </Summary>
Public string TableName
{
Get {return tableName ;}
Set {tableName = value ;}
}

Private string columnName;
/// <Summary>
/// Chinese column name
/// </Summary>
Public string ColumnName
{
Get {return columnName ;}
Set {columnName = value ;}
}
}

I have clearly written in the annotations. One attribute in the Custom feature is the actual database table name corresponding to the object, and the other is the corresponding Chinese column name.
2. Use custom features in entities
 

Code
/// <Summary>
///

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.