Brandon Brandon - 2 months ago 9
C# Question

Can I automatically indent-align code in Visual Studio?

I don't know if there's a name for it, but I'd like to automatically indent(/tab?)-align my source for a large related block of code. Like so:

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)},
};


After:

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)},
};


I know of the Ctrl+K, Ctrl+F as suggested here, and I use that all the time but it's not what I'm looking for.

I've tried tabbing over the code manually but I don't want to do that every time.

I'm looking for a Visual Studio extension.

Answer

I was using Code Alignment VisualStudio extention for such purpose.

Here is what it can do(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";
Comments