How to format complex chained Linq statements for readibility?
Posted
by
Joan Venge
on Stack Overflow
See other posts from Stack Overflow
or by Joan Venge
Published on 2011-02-28T23:11:13Z
Indexed on
2011/02/28
23:24 UTC
Read the original article
Hit count: 171
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?
© Stack Overflow or respective owner