C#静态类的两个名称

Ran*_*all 0 c# static-classes

它非常懒惰,但我想知道是否有可能让两个名字本质上指向同一个静态类.

我有一个很长的描述性静态类名BusinessLogicServiceUtility(例如),它在代码中看起来很啰嗦.

我很乐意使用它BLSU作为替代方案,因此我尝试用我的短名称扩展长类:

public static class BLSU : BusinessLogicServiceUtility
{
}
Run Code Online (Sandbox Code Playgroud)

这可能看起来像菜鸟,但事实证明,它不起作用.

看起来好像我可以使用short类中的方法将长方法中的每个方法包装起来,但是有很多方法,这使得它保持痛苦并绕过整个懒惰目标.

有没有办法将一个名称分配给一个静态类,或者其他一些方法只是"扩展"一个静态类?

Ser*_*kiy 8

您可以为类型创建别名:

using BLSU = Your.Namespace.BusinessLogicServiceUtility;
Run Code Online (Sandbox Code Playgroud)

访问类型的成员:

BLSU.SomeStaticMethod();
Run Code Online (Sandbox Code Playgroud)

使用C#6,您甚至可以更进一步 - 访问类型的静态成员,不必完全限定类型名称:

using static Your.Namespace.BusinessLogicServiceUtility;
Run Code Online (Sandbox Code Playgroud)

访问类型的成员:

SomeStaticMethod();
Run Code Online (Sandbox Code Playgroud)

进一步阅读:使用指令(C#参考)