更新时间:2023-12-02 21:51:52
没有。扩展方法需要一个对象的一个实例。不过,您可以写周围的 ConfigurationManager中
接口的静态包装。如果实施包装,不需要扩展方法,因为你可以直接添加方法。
No. Extension methods require an instance of an object. You can however, write a static wrapper around the ConfigurationManager
interface. If you implement the wrapper, you don't need an extension method since you can just add the method directly.
public static class ConfigurationManagerWrapper
{
public static ConfigurationSection GetSection( string name )
{
return ConfigurationManager.GetSection( name );
}
.....
public static ConfigurationSection GetWidgetSection()
{
return GetSection( "widgets" );
}
}