管理

扩展名工具类 - C#小函数类推荐

Posted on 2024-08-03 18:00  lzhdim  阅读(10145)  评论(0编辑  收藏  举报

       此文记录的是扩展名支持工具类。

/***

    扩展名工具类

    Austin Liu 刘恒辉
    Project Manager and Software Designer

    E-Mail: lzhdim@163.com
    Blog:   http://lzhdim.cnblogs.com
    Date:   2024-01-15 15:18:00

    使用说明:
        1、在类里新建一个对象;
        ExtensionUtil _ExtensionUtil = new ExtensionUtil(new List<string>
        {
            ".exe",
            ".dll",
            ".ico"
        });

        2、判断是否在支持列表中;
        bool isSupport = _ExtensionUtil.IsSupport(".ico");

***/

namespace Lzhdim.LPF.Utility
{
    using System.Collections.Generic;

    /// <summary>
    /// 扩展名工具类
    /// </summary>
    public class ExtensionUtil
    {
        private List<string> _ListSupportExt = null;

        /// <summary>
        /// 扩展名工具类
        /// </summary>
        /// <param name="listSupportExt">是否支持的扩展列表</param>
        public ExtensionUtil(List<string> listSupportExt)
        {
            this._ListSupportExt = listSupportExt;
        }

        /// <summary>
        /// 是否扩展名支持的列表
        /// </summary>
        public List<string> ListSupportExt
        {
            get => this._ListSupportExt;
        }

        /// <summary>
        /// 判断某扩展名是否在支持列表里
        /// </summary>
        /// <param name="ext">扩展名,带.号</param>
        /// <param name="listExt">列表</param>
        /// <returns>true 支持;false 不支持</returns>
        public bool IsSupport(string ext)
        {
            if (_ListSupportExt.Contains(ext))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}

 

Copyright © 2000-2022 Lzhdim Technology Software All Rights Reserved