Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6070927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:59:20+00:00 2026-05-23T09:59:20+00:00

Changetype can not change to type create<Convert.ChangeType(type)>(type); using System; using System.Collections.Generic; using System.Linq; using

  • 0

Changetype can not change to type create<Convert.ChangeType(type)>(type);

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<Order>(order_element, order_instance);
            //create<Order>(order_element);

            xdoc.Root.Add(top2);
            xdoc.Save("./FIX.xml");
            while (true)
            { }
        }
        //protected static void create<T>(XElement root) where T : new()
        protected static void create<T>(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<Type.GetType(type)>(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<Type.GetType(type)>(child);
                }

                Console.WriteLine(memberinfo.Name + " "
                        + memberinfo.PropertyType.ToString().Split('.')[1].ToString() + " "
                    //+ memberinfo.GetValue(instance, null).ToString() + " "
                        + memberinfo.PropertyType);
            }
            return;
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:59:20+00:00Added an answer on May 23, 2026 at 9:59 am

    What you are trying to do with generics is impossible if the type you need is not T.

    The value that goes where you are asking for needs to be a generic value or a value known at compile time.

    That means your only choice is:

    create<T>(root);
    

    Or:

    create<PureTypeName>(root);
    

    Or adding other generic parameters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to cast a System.__ComObject to an interface type using reflection. I have
I am using Convert.ChangeType() to convert from Object (which I get from DataBase) to
I would like to implement conversion between two library classes by Convert.ChangeType in C#.
I'm using the below code to listen for change events of a file i
I cannot figure out why this is not working. Can anyone explain to me
I'm setting fields data via reflection. And I have a problem to convert string
In Perl programming, what is the relevance of variable declaration, when we can change
Have you ever tried to use the Convert.ChangeType() method to convert a value to
is it possible to change type of a attribute after it has been created.
I mean, I want to convert this: string a = 24; Convert.ChangeType(a, typeof(decimal?)) But

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.