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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T19:33:48+00:00 2026-05-18T19:33:48+00:00

I am doing a project that where I need to register all the properties,

  • 0

I am doing a project that where I need to register all the properties, because of the system being so huge it would require a lot of work to register all the properties that i want to be dependent for the purpose of Xaml.

The goal is to find all properties that are on the top of the tree.

so basically

public class A{
    public int Property1 { get; set; }
}

public class B : A{
    public int Property2 { get; set; }
    public virtual int Property3 { get; set; }
}

public class C : B{
    public override int Property3 { get; set; }
    public int Property4 { get; set; }
    public int Property5 { get; set; }
}

The end result would be something like this

A.Property1  
B.Property2  
B.Property3  
C.Property4  
C.Property5  

If you notice I don’t want to accept overridden properties because of the way I search for the properties if I do something like this

C.Property3 for example and it cannot find it it will check C’s basetype and there it will find it.

This is what I have so far.

public static void RegisterType( Type type )
{
    PropertyInfo[] properties = type.GetProperties( BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.GetProperty | BindingFlags.SetProperty );

    if ( properties != null && properties.Length > 0 )
    {
        foreach ( PropertyInfo property in properties )
        {
            // if the property is an indexers then we ignore them
            if ( property.Name == "Item" && property.GetIndexParameters().Length > 0 )
                continue;

            // We don't want Arrays or Generic Property Types
            if ( (property.PropertyType.IsArray || property.PropertyType.IsGenericType) )
                continue;

            // Register Property
        }
    }
}

What I want are the following:

  • Public properties, that are not overridden, not static, not private
  • Either get and set properties are allowed
  • They are not an array or a generic type
  • They are the top of the tree ie C class in the example is the highest (The property list example is exactly what I am looking for)
  • They are not an indexer property ( this[index] )
  • 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-18T19:33:48+00:00Added an answer on May 18, 2026 at 7:33 pm

    In order to ignore inherited members, you can use the BindingFlags.DeclaredOnly flag, which you’re already doing.

    But when properties are overridden, they are re-declared by the derived class. The trick is to then look at their accessor methods to determine if they are in fact overridden.

    Type type = typeof(Foo);
    
    foreach ( var property in type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)) {
        var getMethod = property.GetGetMethod(false);
        if (getMethod.GetBaseDefinition() == getMethod) {
            Console.WriteLine(getMethod);
        }
    }
    

    If the property is overridden, its ‘getter’ MethodInfo will return a different MethodInfo from GetBaseDefinition.

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

Sidebar

Related Questions

We have a project that will need to work in IE6,7,8. I'm not that
I've been doing some work lately on a project that makes extensive use of
In a project that I am doing I need to reach floating indexed elements
Currently am doing project on Family Business. In that I need some video calling
I'm doing a project that involves speech recognition. But here i don't just need
I am doing project using Java and in that I need to reload whole
I'm currently doing a project that has to be multi-lingual. I need to be
I'm working on a project that I need to eliminate all references to the
I'm doing a homework project that requires this: Below you will find the code
For a new project that I'm doing in PHP I've created an SQLMethods class

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.