155144

2008年5月12日14时28分

导航

22.使用Castle时,如何获取自定义类的单个属性的PropertyAttribute.Column

    最近看了下Castle,其中在自定义类时加了很多特性,用于实现实体与数据库表的关联.
    因为对特性接触不多,所以不知道怎么使用.现在找到答案了;)记录下来.

例如:
可以通过如下方法获取属性Id的特性:
BugETT be = new BugETT();
(TypeDescriptor.GetProperties(be)["Id"].Attributes[typeof(PropertyAttribute)]  as PropertyAttribute).Column 

感谢 Colin Han 提供的答案.

 /////////////////////////////////////////////
自定义类: 

    [ActiveRecord("TB_BUG")]
    public class BugETT
    {
        
        private Int32 m_Id;
        

        public BugETT(){}


        [Property("BUG_ID")]
        public Int32 Id
        {
            get { return m_Id; }
            set { m_Id = value; }
        }

}
////////////////////////////////////

posted on 2008-05-21 17:18  155144  阅读(417)  评论(1编辑  收藏  举报