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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:00:46+00:00 2026-05-29T11:00:46+00:00

I have constructed a generic method which deserialiazes an object in the following manner:

  • 0

I have constructed a generic method which “deserialiazes” an object in the following manner:

public class AClass
{
   public int Id {get; set;}
   public string Name {get;set;}
}


public class NestingClass
{
  public string Address {get; set;}
  List<AClass> Classes {get; set;}
}

the output if a list of keyvaluepair : NestingClass Value: none, AddressNestingClass value,
List1.Generic.Collections ClassesNestingClass none, IdAClassNestingClass value, NameAClassNestingClass value.

I manage to get the types of all , but with the values is a little harder because while using propertyInfo.GetValue() i cannot use always the object, e.g for the propertyInfos of a AClass the object (which is the type which forms the list of classes) the object should be of type AClass. Using “this” also does not work . I get the object doesn’t match the target object.
What I would need is some sort of mechanism of “slicing” through the object passed as a generic parameter and try to get the values in that manner.
The code is something like:

    public List<KeyValuePair<string,string>> Process(object foo)
    {

        if (foo == null)
            return new List<KeyValuePair<string,string>>();
        var result = List<KeyValuePair<string,string>>();

        var types = new Stack<Helper>();
        types.Push(new Helper { Type = o.GetType(),Name = string.Empty, Value = string.Empty });

        while (types.Count > 0)
        {
            Helper tHelper = types.Pop();
            Type t = tHelper.Type;
            result.Items.Add(new KeyValuePair { Key = tHelper.Name, Value = tHelper.Value });
            if (t.IsValueType || t == typeof(string))
                continue;

            if (t.IsGenericType)
            {
                foreach (var arg in t.GetGenericArguments())
                    types.Push(new TypeHelper { Type = arg, Name = string.Empty });
                continue;

            }

                foreach (var propertyInfo in t.GetProperties())
                {
//here comes the issue                   
                    types.Push(new TypeHelper { Type = propertyInfo.PropertyType, Name = propertyInfo.Name + propertyInfo.DeclaringType.Name, Value= propertyInfo.GetValue(this,null).ToString() });
                }
            }

            return result;
        }
  • 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-29T11:00:47+00:00Added an answer on May 29, 2026 at 11:00 am

    It seems you’re attempting to get property values from the types represented by your generic property’s types. This is not possible because you have to have an instance to have values to get. There is no instance associated with Type parameters so there are no property values to get.

    Maybe if you can provide more context to what you’re trying to achieve, we can help you get there.

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

Sidebar

Related Questions

Greetings, I have a particular object which can be constructed from a file, as
I have the following example-class: public class MyClass<T> { public IList<T> GetAll() { return
I have done a few projects lately using a Database Object super class which
I have a generic class HierarchicalBusinessObject. In the constructor of the class I pass
Hi I have a question about this pointer, when an object is constructed, when
Suppose, I have a lot of classes, which are constructed using Java reflection (for
In kiama a generic dup method is defined which copies Product objects and applies
Ok so i have the following code setup which seems to work fine: user
I have a class reflecting my dbml file which extends DataContext, but for some
I may be going about this backwards... I have a class which is like

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.