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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:08:02+00:00 2026-06-18T10:08:02+00:00

I am using the code in https://stackoverflow.com/a/531388/528131 to successfully retrieve all the properties of

  • 0

I am using the code in https://stackoverflow.com/a/531388/528131 to successfully retrieve all the properties of an object instance from a base, the problem being that the derived type’s properties are being iterated over first. Due to the nature of the protocol, i need the base properties first.

x |
y | B
z |
w | A

B and A are classes, B derives from A. x, y, z are properties from B and w is a property from A

This is a scheme of how A.GetProperties(); is returning. I need this instead:

w | A
x |
y | B
z |

Is there any way to get the fields in that order EXACTLY?

  • 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-06-18T10:08:04+00:00Added an answer on June 18, 2026 at 10:08 am

    The fields in a type are not “ordered”. The ordering of the items in those methods is an implementation detail and relying on them is strongly discouraged.

    You should order the items yourself, with the expectation that they could start at any position, to ensure your program is robust instead of fragile.

    Since each property can be asked for the type that declares it you can create a lookup at the start that gives a number to each class in the hierarchy from the type you start with all the way up to object by walking the BaseType property of Type and order by the lookup value of the declaring type of each property:

    public static IEnumerable<PropertyInfo> GetOrderedProperties(Type type)
    {
        Dictionary<Type, int> lookup = new Dictionary<Type, int>();
    
        int count = 0;
        lookup[type] = count++;
        Type parent = type.BaseType;
        while (parent != null)
        {
            lookup[parent] = count;
            count++;
            parent = parent.BaseType;
        }
    
        return type.GetProperties()
            .OrderByDescending(prop => lookup[prop.DeclaringType]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using code from this answer: https://stackoverflow.com/a/6501353/494901 Basically when the timer ends, I want
Using the code from this answer: https://stackoverflow.com/a/9744961/514773 I've noticed that any time I enter:
I am trying to compile a code in C++ using code from : https://stackoverflow.com/questions/5953979/sending-and-receiving-array-using-mpi-part-2
I'm using the following code to logout from Facebook. string url = string.Format(https://m.facebook.com/logout.php?confirm=1&next={0}&access_token={1}, ConfigurationManager.AppSettings[Facebooklogout],
Right now I'm using this code to upload files to Google Drive: https://stackoverflow.com/a/11657773/1715263 It
I am able to fetch contacts using this code https://stackoverflow.com/a/1780818/992774 , it works perfectly
(Somewhat of a follow on from the post (which remains unanswered): https://stackoverflow.com/q/6197829/314661 ) Using
From this answer https://stackoverflow.com/a/6457528/299110 I'm using ctrl.PreRender += (sender, e) => ControlPreRender(ctrl, rule); to
I am developing an Django application using the Django 1.3.1 release : https://code.djangoproject.com/browser/django/tags/releases/1.3.1 I
copy('https://graph.facebook.com/$fbid/picture?type=large', 'images/$fbid.jpg'); i am using the above code to store the image locally ..

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.