我能在Visual Studio中自动缩进对齐代码吗?

5

我不知道这个东西有没有名字,但是我想让一个大的相关代码块自动缩进/对齐。比如:

Before:

this._strategies = new Dictionary< Type, IStrategy >
{
    {typeof( Station ), new StationStrategy(this)},
    {typeof( Turnout ), new TurnoutStrategy(this)},
    {typeof( EndOfLine ), new EndOfLineStrategy(this)},
    {typeof( Chainage_Equality ), new ChainageEqualityStrategy(this)},
    {typeof( Track_Connector ), new TrackConnectorStrategy(this)},
    {typeof( Multimeter ), new MultimeterStrategy(this)},
    {typeof( Power_Rail_Gap ), new PowerRailGapStrategy(this)},
    {typeof( EndOfWire ), new EndOfWireStrategy(this)},
    {typeof( Grounding_Point ), new GroundingPointStrategy(this)},
    {typeof( Busbar ), new BusbarStrategy(this)},
    {typeof( AARU ), new AutomaticAssuredReceptivityUnitStrategy(this)},
    {typeof( TPS ), new TractionPowerSubstationStrategy(this)},
    {typeof( AutoTransformer ), new AutotransformerStrategy(this)},
    {typeof( Energy_Storage ), new EnergyStorageStrategy(this)},
};

之后:

this._strategies = new Dictionary< Type, IStrategy >
{
    {typeof( Station ),             new StationStrategy(this)},
    {typeof( Turnout ),             new TurnoutStrategy(this)},
    {typeof( EndOfLine ),           new EndOfLineStrategy(this)},
    {typeof( Chainage_Equality ),   new ChainageEqualityStrategy(this)},
    {typeof( Track_Connector ),     new TrackConnectorStrategy(this)},
    {typeof( Multimeter ),          new MultimeterStrategy(this)},
    {typeof( Power_Rail_Gap ),      new PowerRailGapStrategy(this)},
    {typeof( EndOfWire ),           new EndOfWireStrategy(this)},
    {typeof( Grounding_Point ),     new GroundingPointStrategy(this)},
    {typeof( Busbar ),              new BusbarStrategy(this)},
    {typeof( AARU ),                new AutomaticAssuredReceptivityUnitStrategy(this)},
    {typeof( TPS ),                 new TractionPowerSubstationStrategy(this)},
    {typeof( AutoTransformer ),     new AutotransformerStrategy(this)},
    {typeof( Energy_Storage ),      new EnergyStorageStrategy(this)},
};

我知道Ctrl+K, Ctrl+F可以像这里建议的那样自动缩进,我一直在使用,但这不是我想要的。
我尝试手动制表符缩进代码,但我不想每次都这样做。 我正在寻找一个Visual Studio扩展程序。

这个扩展程序可能会有所帮助,但是所有参与代码的人都必须安装它:https://www.alwaysaligned.net/ - Lucas Trzesniewski
@LucasTrzesniewski AlwaysAligned是我想要的,但每个用户需要40美元。我正在寻找类似于“免费”的东西。 - Brandon
@Brandon 页面顶部还有一个大的“下载免费副本”的按钮。很奇怪。 - Lucas Trzesniewski
@MickyD 当然。这是我解决问题所做的:每次手动制表符。这是我不想做的:每次都要制表符。我会把它添加到问题中。我正在寻找一个VS扩展,应该提到了。谢谢你的投票。 - Brandon
@LucasTrzesniewski 我看漏了,只看到了购买许可证的按钮。 - Brandon
1个回答

4
我使用了Visual Studio扩展程序Code Alignment。以下是它可以做到的(来自官方网站):
    person.FirstName = "Chris";                =>  person.FirstName  = "Chris"; 
    person.Surname = "McGrath";                =>  person.Surname    = "McGrath"; 
    person.Age = 24;                           =>  person.Age        = 24; 
    person.Occupation = "Software Developer";  =>  person.Occupation = "Software Developer"; 
    person.HomeTown = "Brisbane";              =>  person.HomeTown   = "Brisbane";

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接