利用插件整理代码,排序和移除不需要的引用。小心.Net2/.Net4的兼容问题
nnhy authored at 2012-12-08 10:14:21
1.74 KiB
X
using System;
using System.ComponentModel;

namespace XControl
{
    [AttributeUsage(AttributeTargets.All)]
    internal sealed class WebSysDefaultValueAttribute : DefaultValueAttribute
    {
        // Fields
        private bool _localized;
        private Type _type;

        // Methods
        internal WebSysDefaultValueAttribute(string value)
            : base(value)
        {
        }

        internal WebSysDefaultValueAttribute(Type type, string value)
            : base(value)
        {
            this._type = type;
        }

        // Properties
        public override object TypeId
        {
            get
            {
                return typeof(DefaultValueAttribute);
            }
        }

        public override object Value
        {
            get
            {
                if (!this._localized)
                {
                    this._localized = true;
                    string str = (string)base.Value;
                    if (!string.IsNullOrEmpty(str))
                    {
                        object obj2 = SR.GetString(str);
                        if (this._type != null)
                        {
                            try
                            {
                                obj2 = TypeDescriptor.GetConverter(this._type).ConvertFromInvariantString((string)obj2);
                            }
                            catch (NotSupportedException)
                            {
                                obj2 = null;
                            }
                        }
                        base.SetValue(obj2);
                    }
                }
                return base.Value;
            }
        }
    }
}