.net使用自定義類屬性實例(2)_.Net教程

      編輯Tag賺U幣
      教程Tag:暫無Tag,歡迎添加,賺取U幣!

      推薦:.NET實現在網頁中預覽Office文件的3個方法
      近日公司要搞一個日常的文檔管理的東東,可以上傳、下載各種文件,如果是office文件呢還必須得支持預覽功能,其他的都好說但是唯獨office預覽功能比較麻煩,但是不能不做,廢話不多說了一步步來吧。分析了下網易郵箱的文件預覽功能,他用的是微軟的組件,最早叫Office

       

      代碼如下: [Table("Wincms_Dictionary")]            ///映射到數據庫的Wincms_Dictionary表
      public class Wincms_Dictionary : BaseEntity
      {
               private int _DictionaryId;
       
               public Wincms_Dictionary()
               {
               }
       
              [Field("DictionaryId",DbType.Int32)]                ///映射到數據庫的Wincms_Dictionary表中的字段
              public int DictionaryId
              {
                  get { return this._DictionaryId; }
                  set
                  {
                      this._DictionaryId = value;
                  }
              }
      }
       
      ///基于實體類獲取實體對應的表名稱和字段名稱
      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

      分享:asp.net中控制反轉怎么理解?
      對IOC的解釋為:Inversion of control is a common characteristic of frameworks, so saying that these lightweight containers are special because they use inversion of control is like saying my car is special because it has wheels. 我想對這一概念執行

      共2頁上一頁12下一頁
      來源:模板無憂//所屬分類:.Net教程/更新時間:2014-10-15
      相關.Net教程