How to convert string into type?
<p>Changetype can not change to type
create &lt; Convert.ChangeType(type)>(type);</p>

<pre><code>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Xml.Linq;
//using System.Collections.Generic;

using System.Reflection;

namespace FixUtil
{
    class Program
    {
        static void Main(string[] args)
        {
            FIXMessage fix = new FIXMessage();
            fix.top1 = "FIXML";
            fix.top2 = "FIXMLMessage";
            XMLUtil go = new XMLUtil(fix);

            XDocument xdoc = new XDocument(new XDeclaration("1.0", "UTF-8", "yes"), new XElement("FIXML"));

            XElement top2 = new XElement("FIXMLMessage", null);
            XElement Header = go.createHeader();
            top2.Add(Header);
            XElement ApplicationMessage = go.createApplicationMessage();
            top2.Add(ApplicationMessage);

            XElement order_element = go.createOrder();
            ApplicationMessage.Add(order_element);
            //Order.Add(go.createClOrderID("1968"));

            Order order_instance = new Order();
            order_instance.CIOrdID = "1968";
            order_instance.instrument = new Instrument();
            order_instance.instrument.Symbol = "1171";

            create&lt;Order&gt;(order_element, order_instance);
            //create&lt;Order&gt;(order_element);

            xdoc.Root.Add(top2);
            xdoc.Save("./FIX.xml");
            while (true)
            { }
        }
        //protected static void create&lt;T&gt;(XElement root) where T : new()
        protected static void create&lt;T&gt;(XElement root, T instance) where T : class
        {
            //MethodInfo[] methodInfos = typeof(T).GetMethods(BindingFlags.Public | BindingFlags.Static);

            if (typeof(T).GetProperties().Count() == 0)
                return;
            foreach (PropertyInfo memberinfo in typeof(T).GetProperties())
            {
                string type = memberinfo.PropertyType.ToString().Split('.')[1].ToString();
                XElement child;
                if (type == "String")
                {
                    root.Add(new XElement(memberinfo.Name, memberinfo.GetValue(instance, null)));
                    //root.Add(new XElement(memberinfo.Name, null));
                }
                else
                {
                    child = new XElement(memberinfo.Name, null);
                    root.Add(child);
                    create(child, memberinfo.GetType());
                    //create(child, instance);
                    //create&lt;Type.GetType(type)&gt;(child);
                }

                Console.WriteLine(memberinfo.Name + " "
                        + memberinfo.PropertyType.ToString().Split('.')[1].ToString() + " "
                    //+ memberinfo.GetValue(instance, null).ToString() + " "
                        + memberinfo.PropertyType);
            }
            return;
        }

        protected static void create(XElement root, dynamic instance)
        {
            //return null;
            //root.Add(new XElement(instance, GetValue(instance, null)));
            //child = new XElement(root, null);
            //create(child);
            //MethodInfo[] methodInfos = instance.GetMethods(BindingFlags.Public | BindingFlags.Static);

            if(instance.GetProperties().Count() == 0)
                return;
            foreach (PropertyInfo memberinfo in instance.GetProperties())
            {
                string type = memberinfo.PropertyType.ToString().Split('.')[1].ToString();
                XElement child;
                if (type == "String")
                {
                    //root.Add(new XElement(memberinfo.Name, memberinfo.GetValue(instance, null)));
                    root.Add(new XElement(memberinfo.Name, null));
                }
                else
                {
                    child = new XElement(memberinfo.Name, null);
                    root.Add(child);
                    create(child, memberinfo.GetType());
                    //create(child, instance);
                    //create&lt;Type.GetType(type)&gt;(child);
                }

                Console.WriteLine(memberinfo.Name + " "
                        + memberinfo.PropertyType.ToString().Split('.')[1].ToString() + " "
                    //+ memberinfo.GetValue(instance, null).ToString() + " "
                        + memberinfo.PropertyType);
            }
            return;
        }
    }
}
</code></pre>
