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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:49:15+00:00 2026-05-24T08:49:15+00:00

Here is the structure: MyClass : SuperClass2 SuperClass2 : SuperClass1 superClass2 is in Product.Web

  • 0

Here is the structure:

MyClass : SuperClass2

SuperClass2 : SuperClass1

superClass2 is in Product.Web and SuperClass1 is in the .NET System.Web assembly

I’m trying to force a value into a private bool field on SuperClass1. But not matter what I try I cannot get the fields to come back from reflection.

I’m using the following code with different BindingFlag combinations but nothing has worked so far. SuperClass1 is an abstract class.

((SuperClass1)this).GetType().GetFields(System.Reflection.BindingFlags.NonPublic);

Notes:
When I use GetProperties() I get back a nice big list but when I specify any bindingflags I get nothing even though there are matching properties. Whats the deal?

Also, the field is not marked internal

Obvisouly I would be using GetField(string name, BindingFlags) but I can’t even get GetFlags() to work.

Update: I’ve tried adding BindingFlags.Instance as suggested but it doesn’t work (as expected anyway). I get back 2 fields that are coming from the class SuperClass1 inherits from. Returns null when used with GetField(string name, Flags)

Here is the code for the base class I’m trying to get the field for

public abstract class BaseValidator : Label, IValidator
  {
    private bool propertiesChecked;
...
}
  • 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-24T08:49:16+00:00Added an answer on May 24, 2026 at 8:49 am

    You can manually go up in the inheritance chain to get the base fields:

    Given these classes:

    class SuperClass1
    {
        private int myField;
    }
    
    class SuperClass2 : SuperClass1
    {
    }
    
    class MyClass : SuperClass2
    {
    
    }
    

    This should work:

    var myObj = new MyClass();
    var myField = typeof(MyClass).BaseType
                                 .BaseType
                                 .GetField("myField", BindingFlags.Instance | BindingFlags.NonPublic);
    

    There’s a more generic solution in this SO answer: Not getting fields from GetType().GetFields with BindingFlag.Default

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

Sidebar

Related Questions

Here is the structure of the web site: PHP index file //my class for
last time I asked how to populate a data structure here . Now I
I have a complex form in Ruby on Rails 2.3.5, here's the structure for
here is my directory structure. /user/a /user/b /user/b inside folder a,b,c there is a
Here I have: Public Structure MyStruct Public Name as String Public Content as String
Here is a table structure (e.g. test): Field Name Data Type id BIGINT (20)
Here is my data structure alt text http://luvboy.co.cc/images/db.JPG when i try this sql select
Here's my problem.I have 2 xmlfiles with identical structure, with the second xml containing
Here is the example with comments: class Program { // first version of structure
Here's the situation: I'm developing a simple application with the following structure: FormMain (startup

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.