c# - 是否建议在静态类本身中包含扩展方法?

标签 c# extension-methods

我有:

public static class DataManager
{
    private static Dictionary<string, DataTable> dataTables;

    //    extension method
    public static DataTable GetTable ( this string TableName )
    {
        return dataTables[ TableName ];
    }

}

我不想公开 Dictionary 集合,这就是我想完成此任务的方式。在我的调用方法中:

DataTable GetTable (string TableName)
{
    return TableName.GetTable();
}

有没有其他方法我应该或可以做到这一点?或者这是可以接受的吗?

最佳答案

我认为这不是一个好主意,因为您的方法string(扩展方法会声明的内容)进行操作,它对数据管理器。所以在这种情况下只使用静态方法。

关于c# - 是否建议在静态类本身中包含扩展方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4770454/

相关文章:

c# - 未优化的 IEnumerable<>.Last with predicate

c# - Salesforce REST API 是否像 SOAP API 一样一次只允许一个连接?

C# 调用基础构造函数

c# - 可以在 MySQL 中使用 AES_DECRYPT() 解密的 ASP.NET 中的加密

c# - 在 WHERE 子句中操作可选参数

c# - 空闲时间后隐藏鼠标光标

c# - 扩展方法冲突

c# - LINQ、Lambda、C#、扩展方法

c# - 在扩展方法中使用新对象更新 IEnumerable

c# - 在运行时修改 linq 查询