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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:43:44+00:00 2026-05-23T20:43:44+00:00

I want to know if something like this is possible: I’ve overriden a property

  • 0

I want to know if something like this is possible: I’ve overriden a property of a base class, which is auto-implemented. I’ve supplied logic in the override to resolve “missing” properties against default settings.

Now, I want to use reflection to check whether the default value is used or some “actual” value. In other words, I need to check if base.Property is null, but by using reflection. This doesn’t work, it simply gets the sub-class value (which is resolved against defaults, so not null).

var property = this.GetType().GetProperty(e.PropertyName);
if(property.GetValue(this, null) == null))
    OnPropertyChanged(e.PropertyName);

Also tried:

var property = this.GetType().BaseType.GetProperty(e.PropertyName);
if(property.GetValue(this, null) == null))
    OnPropertyChanged(e.PropertyName);

Is it possible using reflection to access the base class value?

UPDATE:

Following advice from comments, I tried the following, just for kicks.

var method1 = this.GetType().BaseType.GetMethods().First(x => x.Name.Contains(e.PropertyName));
var method = this.GetType().BaseType.GetProperty(e.PropertyName).GetGetMethod();
var methodValue = method1.Invoke(this, null);

Both of these still return the “derived” value, while at the same time base.Property returns 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-05-23T20:43:46+00:00Added an answer on May 23, 2026 at 8:43 pm

    It is possible, although as far as I know there’s no way to do it without emitting your own IL, basically using the call instruction rather than callvirt.

    Note that if you need to go to these lengths to make your design work then that’s a sign that you’re probably doing something wrong somewhere!

    Anyway, here’s a contrived example. (Error-checking etc omitted for brevity.)

    var derived = new DerivedClass();
    Console.WriteLine(derived.GetBaseProperty("Prop"));    // displays "BaseProp"
    
    // ...
    
    public class BaseClass
    {
        public virtual string Prop { get; set;}
    }
    
    public class DerivedClass : BaseClass
    {
        public override string Prop { get; set;}
    
        public DerivedClass()
        {
            base.Prop = "BaseProp";
            this.Prop = "DerivedProp";
        }
    
        public object GetBaseProperty(string propName)
        {
            Type t = this.GetType();
            MethodInfo mi = t.BaseType.GetProperty(propName).GetGetMethod();
    
            var dm = new DynamicMethod("getBase_" + propName, typeof(object), new[] { typeof(object) }, t);
    
            ILGenerator il = dm.GetILGenerator();
            il.Emit(OpCodes.Ldarg_0);
            il.Emit(OpCodes.Call, mi);
            if (mi.ReturnType.IsValueType) il.Emit(OpCodes.Box, mi.ReturnType);
            il.Emit(OpCodes.Ret);
    
            var getBase = (Func<object, object>)dm.CreateDelegate(typeof(Func<object, object>));
            return getBase(this);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to know that, is something like this, possible? : #test{ background-color: red;
I don't even know if this is possible. I want to do something like:
Summary: I want to know if it is possible to do something like this:
i want to know if is possible to do something like this in mysql:
Does anyone know if something like this is possible? Do a quick search, using
I want to know if there is a way to use something like this:
What I want to know is, if I were to execute something like ping
I want to know i can do something similar to this (not working) code
Im creating a news-like app and I want to know is is possible to
i dont know if this is possible, but i will explain what i want

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.