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 False, I need to create two XElements as descendants of Scale, if it is True, i don’t need these elements.
<Scale DynamicScale="False">
<LowScale>0</LowScale>
<HighScale>10000</HighScale>
</Scale>
Is there any way to add an If 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.
new XElement("Scale",
new XAttribute("DynamicScale", c.DynamicScale),
if (c.DynamicScale == false)
{
new XElement("LowScale", c.LowScale),
new XElement("HighScale", c.HighScale),
})
Use the ternary operator