<p>Helo!</p>

<p>Is this possible to use string value of one node which tells what type of field is presented in another node using LINQ to XML?</p>

<p>For example:</p>

<pre><code>&lt;node&gt;
  &lt;name&gt;nodeName&lt;/name&gt;
  &lt;type&gt;string&lt;/type&gt;
&lt;/node&gt;
&lt;node&gt;
  &lt;name&gt;0&lt;/name&gt;
  &lt;type&gt;bool&lt;/type&gt;
&lt;/node&gt;
&lt;node&gt;
  &lt;name&gt;42&lt;/name&gt;
  &lt;type&gt;int&lt;/type&gt;
&lt;/node&gt;
</code></pre>

<p>Thanks in advance</p>

Well, you won't get a nice statically typed API given that the type information is only known at execution time - but you could easily write an extension method on XElement which looks for the appropriate subelements and returns
```
System.Object
```
. For instance (untested):
```
```
public static object ParseValue(this XElement element)
{
    XElement name = element.Element("name");
    XElement type = element.Element("type");
    // Insert error handling here :)

    switch (type.Value)
    {
        case "int":
            return int.Parse(name.Value);
        case "string":
            return name.Value;
        case "bool":
            return name.Value == "1"; // Or whatever
        default:
            throw new ArgumentException("Unknown element type " + type.Value);
    }
}
```
```
It's not how I'd design a data format, but if it's being thrust upon you...