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

The Archive Base Latest Questions

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

I have an abstract class with an abstract property that is set to have

  • 0

I have an abstract class with an abstract property that is set to have both Get and Set. I know I’ll always want to be able to get this property from derived classes but there are some cases where it doesn’t make sense to set this property in certain types of derived classes.

I can’t just omit the Set accessor in a derived class (see code example below). I could override the set accessor in a derived classes to do nothing with the values passed by the user. But is there another way that actually make the property in a specific derived class read only? Ultimately I’m displaying these properties in a property grid and I don’t want the user to be entering values into a field that is going to do nothing. Maybe I just attribute the property as read only in specific derived classes?

Also I’d really really rather not mess with any of the type descriptor stuff to get properties to display correctly in a property grid, such as overriding ICustomTypeDescriptor.

public abstract class MyClass
{
    public abstract string MyProperty
    {
        get;
        set;
    }
}

public abstract class MyDerivedClass
{
    public override string MyProperty
    {
        //VS complains that the Set accessor is missing
        get;
    }
}
  • 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-11T19:44:19+00:00Added an answer on May 11, 2026 at 7:44 pm

    You should not do this. What you are saying by defining your getter and setter in the abstract class is “you must implement this if you want to inherit from me.” Then you are asking, “how can I made a derived class ignore this rule.”

    The answer is that if you have a situation that every derived class needs a getter, put that in the abstract class and let the derived class decide if they will implement a setter or not by leaving it out of the abstract class.

    Or alternatively, you can create two more classes that derive from the initial abstract class, one that implement the setter and one that does not and then have your derived class generalize the one of those that makes sense, but that is overkill I think.

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

Sidebar

Related Questions

I'm creating an abstract class to derive from. I have a Value property that
I have two classes that are derived from an abstract generic class, which is
I have an abstract class that other classes are inheriting this. public abstract class
I have an abstract generic class that defines a generic dependency property the type
My problem is that I want to stub a property in my abstract class,
I have a base class that looks like this: public abstract class MyBaseClass {
I have an abstract superclass with a property that must be set by the
I have an abstract class named PersonAbstract . It has an abstract property called
Let say I have abstract class called: Tenant and Customer. The tenant in this
I have an abstract class that implements IDisposable, like so: public abstract class ConnectionAccessor

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.