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>
///