.net使用自定义类属性实例

2019-05-23 07:52:21丽君

            }
        }
}
 
///基于实体类获取实体对应的表名称和字段名称
public class Test
{
 
       public static void main(string[] args)
        {
               Wincms_Dictionary dict=new Wincms_Dictionary();
               Console.WriteLine("表名称:"+GetTableName(dict));
               Console.WriteLine("字段名称:"+GetFieldName(dict,"DictionaryId"));
               Console.Read();
        }
 
       ///获取实体表名称
       public  static string GetTableName(BaseEntity entity)
       {
                return entity.GetTableName();
       }
 
       ///获取实体字段名称
       public static string GetFieldName(BaseEntity entity,string propertyName)
       {
              FieldAttribute fieldAttribute=entity.GetFieldAttribute(propertyName);
              return fieldAttribute.FieldName;
       }
}
输出结果为:

表名称:Wincms_Dictionary
字段名称:DictionaryId

希望本文所述对大家的.net程序设计有所帮助。