How to format complex chained Linq statements for readibility?
- by Joan Venge
I have some code like this:
var effects = xElement.Elements ( "Effects" ).Elements ( "Effect" ).Select (
e => new Effect (
( EffectType ) Enum.Parse ( typeof ( EffectType ), ( string ) e.Elements ( "Type" ).FirstOrDefault ( ) ),
e.Elements ( "Options" ).Any ( )
? e.Elements ( "Options" ).Select ( o => ( object ) o.Elements ( "Option" ).Select ( n => n.Value ).First ( ) )
: null ) )
.ToList ( );
But currently this doesn't look as readable and I am not sure where I should add a new line and/or indent for readability.
Any suggestions I could use to make consistent, readable linq blocks?