⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 csscollectionconverter.cs

📁 浏览器端看到树型目录结构,用户可以完整地看到像windows资源管理器一样的效果
💻 CS
字号:
//------------------------------------------------------------------------------
// Copyright (c) 2000-2003 Microsoft Corporation. All Rights Reserved.
//------------------------------------------------------------------------------

namespace Microsoft.Web.UI.WebControls
{
    using System;
    using System.Globalization;
    using System.ComponentModel;
    using System.ComponentModel.Design.Serialization;

    /// <summary>
    /// Allows the CssCollection to convert to/from string objects.
    /// </summary>
    public class CssCollectionConverter : TypeConverter
    {
        /// <summary>
        /// Determines if a CssCollection can be converted from a type.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="sourceType">The source type.</param>
        /// <returns>true if possible, false otherwise.</returns>
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            if (sourceType == typeof(string))
            {
                return true;
            }

            return base.CanConvertFrom(context, sourceType);
        }

        /// <summary>
        /// Determines if a CssCollection can be converted to a type.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="destinationType">The destination type.</param>
        /// <returns>true if possible, false otherwise.</returns>
        public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
        {
            if (destinationType == typeof(string))
            {
                return true;
            }
            else if (destinationType == typeof(InstanceDescriptor))
            {
                return true;
            }

            return base.CanConvertTo(context, destinationType);
        }

        /// <summary>
        /// Converts an object to a CssCollection.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="culture">The culture.</param>
        /// <param name="value">The value.</param>
        /// <returns>A new CssCollection or null.</returns>
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value is string)
            {
                return new CssCollection((string)value);
            }

            return base.ConvertFrom(context, culture, value);
        }

        /// <summary>
        /// Converts a CssCollection to a new type.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="culture">The culture.</param>
        /// <param name="value">The value of the CssCollection.</param>
        /// <param name="destinationType">The destination type.</param>
        /// <returns>The new object or null.</returns>
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType == typeof(string))
            {
                return ((CssCollection)value).CssText;
            }
            else if (destinationType == typeof(InstanceDescriptor) && (value is CssCollection))
            {
                return new InstanceDescriptor(typeof(CssCollection).GetConstructor(new Type[] { typeof(string) }), new string[] { ((CssCollection)value).CssText } );
            }

            return base.ConvertTo(context, culture, value, destinationType);
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -