English versionEnglish
博杨计算机有限公司

AspNetPager分页控件

AspNetPager源代码—CustomAttributes.cs

    1 //AspNetPager分页控件源代码:

    2 //版权所有:陕西省延安市吴起县博杨计算机有限公司 杨涛(Webdiyer)

    3 //此源代码仅供学习参考,不得用于任何商业用途;

    4 //您可以修改并重新编译该控件,但源代码中的版权信息必须原样保留!

    5 //有关控件升级及新控件发布信息,请留意 www.webdiyer.com 。

    6 

    7 using System;

    8 using System.Resources;

    9 using System.ComponentModel;

   10 using System.Web.UI;

   11 using System.Web.UI.WebControls;

   12 

   13 namespace Wuqi.Webdiyer

   14 {

   15     #region Custom Attributes

   16 

   17     [AttributeUsage(AttributeTargets.All)]

   18     internal sealed class ANPDescriptionAttribute : DescriptionAttribute

   19     {

   20         public ANPDescriptionAttribute(string text)  : base(text)

   21         {

   22             replaced = false;

   23         }

   24 

   25         public override string Description

   26         {

   27             get

   28             {

   29                 if (!replaced)

   30                 {

   31                     replaced = true;

   32                     DescriptionValue = SR.GetString(DescriptionValue);

   33                 }

   34                 return base.Description;

   35             }

   36         }

   37         private bool replaced;

   38     }

   39 

   40     [AttributeUsage(AttributeTargets.All)]

   41     internal class ANPCategoryAttribute : CategoryAttribute

   42     {

   43         internal ANPCategoryAttribute(string name) : base(name) { }

   44 

   45         protected override string GetLocalizedString(string value)

   46         {

   47             string cat = base.GetLocalizedString(value);

   48             if (null == cat)

   49                 cat = SR.GetString(value);

   50             return cat;

   51         }

   52     }

   53 

   54 

   55     [AttributeUsage(AttributeTargets.All)]

   56     internal class ANPDefaultValueAttribute : DefaultValueAttribute

   57     {

   58         public ANPDefaultValueAttribute(string name)

   59             : base(name)

   60         {

   61             localized = false;

   62         }

   63 

   64         public override object Value

   65         {

   66             get

   67             {

   68                 if (!localized)

   69                 {

   70                     localized = true;

   71                     string defValue = (string)base.Value;

   72                     if (!string.IsNullOrEmpty(defValue))

   73                     {

   74                         return SR.GetString(defValue);

   75                     }

   76                 }

   77                 return base.Value;

   78             }

   79         }

   80         private bool localized;

   81     }

   82 

   83     internal sealed class SR

   84     {

   85         private SR()

   86         {

   87             _rm = new ResourceManager("Wuqi.Webdiyer.AspNetPager", GetType().Assembly);

   88         }

   89 

   90         private ResourceManager Resources

   91         {

   92             get { return _rm; }

   93         }

   94 

   95         private ResourceManager _rm;

   96 

   97 

   98         private static SR GetLoader()

   99         {

  100             if (null == _loader)

  101             {

  102                 lock (_lock)

  103                 {

  104                     if (null == _loader)

  105                         _loader = new SR();

  106                 }

  107             }

  108             return _loader;

  109         }

  110 

  111         public static string GetString(string name)

  112         {

  113             SR loader = GetLoader();

  114             string localized = null;

  115             if (null != loader)

  116                 localized = loader.Resources.GetString(name, null);

  117             return localized;

  118         }

  119 

  120         private static SR _loader = null;

  121 

  122         private static object _lock = new object();

  123     }

  124 

  125     /// <summary>

  126     /// AspNetPager type converter used for the design time support

  127     /// </summary>

  128     internal class AspNetPagerIDConverter : ControlIDConverter

  129     {

  130         protected override bool FilterControl(Control control)

  131         {

  132             if (control is AspNetPager)

  133                 return true;

  134             return false;

  135         }

  136     }

  137     #endregion

  138 }