0

Im trying to have a XElement with style like:

<g style="fill-opacity:0.7">

so im doing this:

XElement root = new XElement("g");
root.SetAttributeValue("style",
                from attributes in Child.Attributes
                where char.IsUpper(attributes.Key[0]) & !attributes.Value.ToString().StartsWith(transformNS)
                select new XAttribute("style", attributes.Key + ":" + attributes.Value));

But what i have is

<g style="System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Collections.Generic.KeyValuePair`2[System.String,System.Object],System.Xml.Linq.XAttribute]">

someone can help me?

best regards

user1977936
  • 31
  • 2
  • 13

1 Answers1

0

That's because your are selecting a complete XAttribute as the value of an attribute. You need to iterate over your properties and concenate them into a string. Then use this string as the value of your attribute.

Something like this:

XElement root = new XElement("g");
IEnumerable<string> styleprops = from attributes in Child.Attributes
                                 where char.IsUpper(attributes.Key[0]) & !attributes.Value.ToString().StartsWith(transformNS)
                                 select attributes.Key + ":" + attributes.Value

string value = string.empty;

foreach(string prop in styleprops){
    value += prop + ";";
}

root.SetAttributeValue("style", value);
Kenneth
  • 28,294
  • 6
  • 61
  • 84