【问题标题】:Can I automatically indent-align code in Visual Studio?我可以在 Visual Studio 中自动缩进对齐代码吗?
【发布时间】:2016-09-08 12:58:19
【问题描述】:

我不知道它是否有名称,但我想自动缩进(/tab?)-对齐我的源代码以获取大量相关代码块。像这样:

之前:

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+KCtrl+F 建议 here,我一直使用它,但这不是我想要的。

我尝试过手动切换代码,但我不想每次都这样做。

我正在寻找 Visual Studio 扩展。

【问题讨论】:

  • 此扩展程序可能会有所帮助,但与代码相关的每个人都必须安装它:alwaysaligned.net
  • @LucasTrzesniewski AlwaysAligned 是我想要的,但每位用户 40 美元。我一直在寻找 $Free.99 范围内的东西
  • @Brandon 页面顶部还有一个很大的“下载免费副本”按钮。很奇怪。
  • @MickyD 当然。这是我为解决问题所做的工作:我每次都手动标记字符。这就是我不想做的事情:每次都在字符上制表符。我会把它添加到问题中。我正在寻找一个 VS 扩展,应该提到这一点。感谢您的反对。
  • @LucasTrzesniewski 猜我忽略了,只看到了购买许可证按钮。

标签: c# visual-studio format


【解决方案1】:

我为此目的使用了Code Alignment VisualStudio 扩展。

这是它能做什么(taken from official website)

    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";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-23
    • 2016-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-25
    • 1970-01-01
    • 2021-12-25
    相关资源
    最近更新 更多