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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:49:04+00:00 2026-06-11T00:49:04+00:00

How to get inherited property value using reflection? I try with BindingFlags but still

  • 0

How to get inherited property value using reflection?
I try with BindingFlags but still trigger NullReferenceException

object val = targetObject.GetType().GetProperty("position", BindingFlags.FlattenHierarchy).GetValue(targetObject, null);

position is iherited public property and has a declared value.

EDIT:

class myParent
{
    public float[] position;
    public myParent()
    {
        this.position = new float[] { 1, 2, 3 };
    }
}

class myChild : myParent
{
    public myChild() : base() { }
}

myChild obj = new myChild();
PropertyInfo p = obj.GetType().GetProperty("position", BindingFlags.Instance | BindingFlags.Public); 

I tried with several combinations with BindingFlags but p always is null 🙁 ,

  • 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-11T00:49:06+00:00Added an answer on June 11, 2026 at 12:49 am

    If you use the overload with BindingFlags you have to explicitly specify all the flags what you are interested.

    Also note that: (from MSDN)

    You must specify either BindingFlags.Instance or BindingFlags.Static
    in order to get a return.

    object val = targetObject.GetType()
                 .GetProperty("position", 
                              BindingFlags.FlattenHierarchy | 
                              BindingFlags.Instance | 
                              BindingFlags.Public)
                 .GetValue(targetObject, null);
    

    EDIT:

    You have a position field not a property !.

    (A good place to start learning the difference: Difference between Property and Field in C# 3.0+ especially this answer)

    Change your position to a property:

    public float[] position { get; set; }
    

    Or you use the targetObject.GetType().GetField(... method to retrieve the field.

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

Sidebar

Related Questions

I'm trying to get the value of an inherited CSS property using Javascript. I
In the get section of the inherited property, you could throw a NotImplementedException. But
I’m currently using the @property decorator to achieve getters and setters in a couple
I currently have a TextBox using: <%: Html.TextBox(TextBox1) %> How do I get the
using System; class Program { static void Main() { var p = typeof(MyClass2).GetProperty(Value); var
First let me say, that what I want to do is get the value
How can we access the model's property name when using EditorFor() with a template
Assuming I have an Object Car with one property: Model I would populate the
I'm using the XamlServices.Transform to take an object model and serialize it to Xaml.
I have CustomForm inherited from Form which implements a boolean property named Prop .

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.