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 4321782
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T08:47:25+00:00 2026-05-21T08:47:25+00:00

Please go through the sample code: public T LoadWithChildren<T>(object key, object myObject) where T

  • 0

Please go through the sample code:

    public T LoadWithChildren<T>(object key, object myObject) where T : class, new()
    {
        //T myObject = new T();
        SelectOne(myObject, key);

        /// Caching all non-generic type objects.
        Type objectType = typeof(T);

        PropertyInfo[] propertyInfo = objectType.GetProperties();
        List<object> NonGenericProperty = new List<object>();
        List<object> Parents = new List<object>();
        List<object> Children = new List<object>();

        foreach (PropertyInfo property in propertyInfo)
        {
            if (property.PropertyType.IsPrimitive == false && property.PropertyType.FullName != "System.Byte"
                && property.PropertyType.Name != "System.SByte" && property.PropertyType.Name != "System.Int32"
                && property.PropertyType.Name != "System.UInt32" && property.PropertyType.Name != "System.Int16"
                && property.PropertyType.Name != "System.UInt16" && property.PropertyType.Name != "System.Int64"
                && property.PropertyType.Name != "System.UInt64" && property.PropertyType.Name != "System.Single"
                && property.PropertyType.Name != "System.Double" && property.PropertyType.Name != "System.Char"
                && property.PropertyType.Name != "System.Boolean" && property.PropertyType.Name != "System.Object"
                && property.PropertyType.Name != "System.Object" && property.PropertyType.Name != "System.String"
                && property.PropertyType.Name != "System.Decimal")
            {
                NonGenericProperty.Add(property);
            }
        }

        /// Separate All children 
        foreach (object NonGenericObject in NonGenericProperty)
        {
            /// Checking for child attributes
            foreach (object attribute in ((PropertyInfo)NonGenericObject).GetCustomAttributes(true))
            {
                /// If the attribute is ChildObjectAttribute
                if (attribute is ChildObjectAttribute)
                {
                    Children.Add(NonGenericObject);

                    Type tempType = ((PropertyInfo)NonGenericObject).PropertyType;

                    PropertyInfo[] tempProperty = tempType.GetProperties();


                    // if the child is not a Generic type like list
                    if (((PropertyInfo)NonGenericObject).PropertyType.IsGenericType == false)
                    {
                        foreach (PropertyInfo property in tempProperty)
                        {
                            foreach (object childAttribute in property.GetCustomAttributes(true))
                            {
                                if (childAttribute is ParentObjectAttribute && property.PropertyType == typeof(T))
                                {
                                    /// Set the parent reference of child object to myObject
                                    object childObject = new object();
                                    property.SetValue(childObject, myObject, null);
                                    LoadWithChildren<tempType>(1, childObject);


                                }
                            }
                        }
                    }
                    /*if (((PropertyInfo)NonGenericObject).PropertyType.IsGenericType == true)
                    {
                        foreach(PropertyInfo property )
                        {

                        }
                    }*/
                }
            }
        }

        /// Separate All parents  
        foreach (object NonGenericObject in NonGenericProperty)
        {
            foreach (object attribute in ((PropertyInfo)NonGenericObject).GetCustomAttributes(true))
            {
                if (attribute is ParentObjectAttribute)
                {
                    Parents.Add(NonGenericObject);
                }
            }
        }


        /// Caching all  






        throw new NotImplementedException();
    }

if you see that at the end when the method LoadWithChildren(object key, object myObject) is recursively calling itself, I am trying to use “tempType”, a “Type” object as Type Parameter since the type is not known and reflection is being used to get the type on run time. But its not accepting the “Type” object rather it asks for a class or a parameter less constructor. I would be obliged if someone can help me out. You suggestions, solutions and knowledge would be appreciated.

Regards,
Umair

  • 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-21T08:47:25+00:00Added an answer on May 21, 2026 at 8:47 am

    You are going to have to use MakeGenericMethod() since you don’t know at compile time what type you are going to use:

    MethodInfo method = typeof(WhateverContainsThisMethod).GetMethod("LoadWithChildren");
    MethodInfo mi= method.MakeGenericMethod(tempType);
    mi.Invoke(this, new object[] {1, childObject} );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

please have a look at the following code import java.util.ArrayList; import java.util.List; public class
I am studying the new Async CTP and going through some sample code, I
Please guide me with sample code for sending sms through website. How to include
Please help me with this code - I am basically going through a book
I am working through a code sample, and I just want to hear some
Can you someone please point in me in a direction, sample code or an
First of all: I'm new to programing. Please be detailed if you choose to
i want to generate Key Keypresses programmatically in android. i had gone through sample
Can someone please identify how this site has the effect of sliding through pages?
Please provide a good, thorough tutorial about Java class loading , focusing on how

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.