Linq to XML - Create Xelement only IF something

sneha1234

New Member
I'm new to linq to xml and trying to do the following.I'm creating a new xml, from some objects i receive.I have a XElement called "Scale"There is a Bool Value "DynamicScale", in case it is \[code\]False\[/code\], I need to create two \[code\]XElements\[/code\] as descendants of \[code\]Scale\[/code\], if it is \[code\]True\[/code\], i don't need these elements.\[code\] <Scale DynamicScale="False"> <LowScale>0</LowScale> <HighScale>10000</HighScale> </Scale>\[/code\]Is there any way to add an \[code\]If\[/code\] statement in the middle of the creation of this?Or any other suggestions to deal with this need?This if what I'd like to be able to do (I know it's not possible like this). Any simple way is welcome.\[code\]new XElement("Scale", new XAttribute("DynamicScale", c.DynamicScale), if (c.DynamicScale == false) { new XElement("LowScale", c.LowScale), new XElement("HighScale", c.HighScale), })\[/code\]
 
Back
Top