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

  • SEARCH
  • Home
  • 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 5844743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:20:10+00:00 2026-05-22T12:20:10+00:00

I have a customer class with a sub-class address internal class Customer { public

  • 0

I have a customer class with a sub-class address

internal class Customer    
{
    public int id { get; set; }
    public string name { get; set; }

    [ObjectDefRelation(isSubClass = true)]
    public Addressinformation Addressinformation { get; set; }
}

internal class Addressinformation 
{
    public string street { get; set; }
}

I have a Method to fill this object with data from a xml. Now I want to call this method recursive when its arrive the sub-class Addressinformation. How can I call my generic method with informations from PropertyInfo?

public static T ConvertXmlToClass<T>(XmlDocument xmlDocumentObjectDef, XmlNode xmlNode, ObjectDefRelationAttribute parentClass = null) where T : new()
{
    ObjectDefRelationAttribute defRelationAttribute;
    T xmlToClass = new T();

    foreach (PropertyInfo field in xmlToClass.GetType().GetProperties())
    {
        foreach (Attribute attr in field.GetCustomAttributes(true))
        {
            defRelationAttribute = attr as ObjectDefRelationAttribute;
            if (null != defRelationAttribute)
            {
                if (defRelationAttribute.isSubClass)
                {
                    // 
                    // here I need help to call the recursive method (XXX)
                    //
                    var subClass = Helper.ConvertXmlToClass<XXX>(xmlDocumentObjectDef, xmlNode, defRelationAttribute);
                }
            }
        }
    }
}

I used the best answer with some modification:

Type typeArguments = GetType(field.PropertyType.Namespace + "." + field.PropertyType.Name);
object value = typeof(Helper).GetMethod("ConvertXmlToClass").MakeGenericMethod(typeArguments).Invoke(null, new object[] {xmlDocumentObjectDef, xmlNode, defRelationAttribute});
  • 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-22T12:20:11+00:00Added an answer on May 22, 2026 at 12:20 pm

    It seems that you’ve got a function that converts Type names to Types, something like this:

    Type GetType(string typeName)
    {
        return Type.GetType(typeName);
    }
    

    then you can call this method as:

    object value = typeof(owningType).GetMethod("ConvertXmlToClass").MakeGenericMethod(GetType(typeName)).Invoke(xmlDocumentObjectDef, xmlNode, xmlToClass);
    

    and Use PropertyInfo.SetValue() to set it on the property

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

Sidebar

Related Questions

I have a Customer class. public class Customer { private string _id; private string
I have a Customer which has Addresses: public class Customer { public int Id
Within my application i have a PUBLIC customer class... Public Class Customer Public Name
In my application I have a Customer class and an Address class. The Customer
I have a class with following description: public class Customer { public ISet<Client> Contacts
If I have the following domain object: public class Customer { public virtual Guid
Suppose I have the following types of data: class Customer { String id; //
I have class(Customer) which holds more than 200 string variables as property. I'm using
Say I have a Customer class with the usual properties: CustomerID , Name ,
I have a Customer class that contains a property, MyProperty, which is of a

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.